Given a list of tuples, find the list which belong to same tuple.
Input (Matrix):
int input[][] = {{1,2},{3,4},{7,2},{5,12},{11,3},{9,7}}
Output:
ArrayList of Arraylist: {{1,2,7,9},{3,4,11},{5,12}}
Note: Order of output is not important.
My approach : I used disjoint sets to solve this question. At the end, group with same parent will belong to same list and then we can output the list. Looking for a better approach (if available).
Thanks!
Similar problem: https://leetcode.com/problems/accounts-merge/