### m15s's blog

By m15s, history, 2 months ago,

A given graph represents friendship relations between a group of people. Each node is a person and an edge between any nodes means that the two people are friends. The problem wants us to find a group of 3 or more people such that every member of the group is friends with atleast two other members in the same group. In the case that there are multiple such groups satisfying this, they want us to return any one. In case that there is no such group satisfying the condition, we can return an empty list.

Any ideas for this? I was thinking of working with connected components but i'm not too sure on how to build on that. Please do help me out!! thanks

• -14

 » 2 months ago, # |   -16 I think answer will be a connected component of persons which size>=3.
•  » » 2 months ago, # ^ |   0 No, o-o-o is a trivial counterexample.
 » 2 months ago, # |   0 I think any edge biconnected subgraph with more than 2 nodes is OK
 » 2 months ago, # | ← Rev. 2 →   +10 Firstly, if a solution exists, then there is a connected subgraph satisfying the conditions. (Otherwise, if all solutions returned a subgraph with more than one connected component, then any of the connected components would also satisfy the conditions, which is a contradiction). Therefore, we will only consider connected subgraphs as possible solutions.Also, we can show that the solution must contain a cycle. (If it didn't, then the returned subgraph would be a tree, where the leaves would break the conditions).Finally, we observe that any cycle would satisfy the conditions, as each node would have a degree of 2 in the subgraph. Hence, we can simply find a cycle using any method (e.g. DFS) and return it.