@@ -98,8 +98,8 @@ void merge(int x, int y){
9898 }
9999
100100 /**
101- * this is the code to merge email accounts
102- * if two accounts share at least one email, they belong to same person.
101+ * This code merges email accounts.
102+ * If two accounts share at least one email address , they are considered to belong to the same person and are merged .
103103 * @param accountList
104104 * @return
105105 */
@@ -155,3 +155,25 @@ public List<List<String>> accountsMerge(List<List<String>> accountList) {
155155 }
156156
157157}
158+
159+ /**
160+ *
161+ * this the program for testing the above algorithm
162+ *
163+ public class DisjointSetMain {
164+ public static void main(String[] args) {
165+ List<List<String>> list = new ArrayList<>();
166+ list.add(new ArrayList<>(List.of("abc", "abc@mail.com","abx@mail.com")));
167+ list.add(new ArrayList<>(List.of("abc","abc@mail.com","aby@mail.com")));
168+ list.add(new ArrayList<>(List.of("Mary","mary@mail.com")));
169+ list.add(new ArrayList<>(List.of("John","johnnybravo@mail.com")));
170+ list.add(new ArrayList<>(List.of("John", "johnnybravo@mail.com", "john@mail.com")));
171+ DisjointSet ds = new DisjointSet(list.size());
172+ List<List<String>> ans = ds.accountsMerge(list);
173+ for(List<String> val : ans){
174+ System.out.println(val);
175+ }
176+ }
177+ }
178+
179+ */
0 commit comments