Skip to content

Tag: graph

Scanning input in HashMap of String and ArrayList

I need to add all these cities in a HashMap of String and ArrayList And I am unable to add these , I have the structure So now i need to add banglore and then if banglore is present i will add Hyderabad to the ArrayList and again I’ll scan for the next element again banglore is present so add

Merge sets when two elements in common

This is the follow up of compare sets I have I want to merge the sets when there are two elements in common. For example 0,1,2 and 0,2,6 has two elements in common so merging them to form [0,1,2,6]. Again [0,1,2,6] and [2,6,7] has 2 and 6 common. so merging them and getting [0,1,2,6,7]. The final output shoul…