我怎样才能在方阵中找到组
给定一个方阵,其中每一行代表一个人,每个单元格代表该人是否向另一个人赠送了礼物。例如 (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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论