我怎样才能在方阵中找到组

发布于 2025-01-16 09:51:38 字数 454 浏览 3 评论 0原文

给定一个方阵,其中每一行代表一个人,每个单元格代表该人是否向另一个人赠送了礼物。例如 (0,1) -> 1表示个体0给了个体1一些东西,因此,(1,0)也是->1。 1. 目标是创建一个函数,使其根据每个人的天赋创建群体,遵循以下逻辑:如果 ind 1 向 ind 2 给予某些东西,而 ind 2 向 ind 3 给予某些东西,则 ind 1 到 3 都是其中的一部分团体。

输入是一个矩阵,如下所示:

input
[
    [1,1,0,0], 
    [1,1,1,0], 
    [0,1,1,0], 
    [0,0,0,1]
]

output -> [[0,1,2], [3]]

我在采访中收到这个问题,但我可以解决它,我不是在寻找答案,而是寻找关于我需要知道什么才能解决它的指示。

谢谢

Given a squared matrix where each row represent an individual and each cell whether that person gave a gift to another one. For Example (0,1) -> 1 means individual 0 gave something to individual 1, thus, (1,0) is also -> 1. The goal is to create a function such that it creates groups base on the gift of each individual following the logic that if ind 1 gave something to ind 2 and ind 2 gave something to ind 3 then ind 1 through 3 are part of that group.

The input is a matrix as follow:

input
[
    [1,1,0,0], 
    [1,1,1,0], 
    [0,1,1,0], 
    [0,0,0,1]
]

output -> [[0,1,2], [3]]

I got this question in an interview but I could solve it, I'm not looking for an answer but for pointers on what do i need to know in order to solve it.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文