Very Easily Understandable Java soln in O(nlogn)


#1

public class Solution {
public ArrayList solve(ArrayList A, ArrayList B, ArrayList C)
{
//Create required 3 HMs and one HashSet
HashMap<Integer,Integer> map1=new HashMap<>();
HashMap<Integer,Integer> map2=new HashMap<>();
HashMap<Integer,Integer> map3=new HashMap<>();
HashSet h = new HashSet();
ArrayList arr=new ArrayList<>();
for(int i=0;i<A.size();i++)
{
map1.put(A.get(i),1);
}
for(int i=0;i<B.size();i++)
{
map2.put(B.get(i),1);
if(map1.containsKey(B.get(i)))//checking if num present in HM
{
if(!h.contains(B.get(i)))//checking if num is repeated
arr.add(B.get(i));
h.add(B.get(i));
}

    }
    for(int i=0;i<C.size();i++)
    {
        map3.put(C.get(i),1);
        if(map1.containsKey(C.get(i))||(map2.containsKey(C.get(i))))//checking if num present in HM
        {   
            if(!h.contains(C.get(i)))//checking if num is repeated
            arr.add(C.get(i));
            h.add(C.get(i));
            
        }
    }
    Collections.sort(arr);//Sorting array
    return arr;
}

}