Simple solution using TreeMap Java


#1

public class Solution {
public ArrayList solve(ArrayList A, ArrayList B, ArrayList C) {

    TreeMap<Integer, Integer> tm = new TreeMap<>();
    for(int x: A){
        tm.put(x,1);
    }
    for(int x: B){
        if(tm.containsKey(x) && tm.get(x)%10!=2){
            tm.put(x,tm.get(x)*10 + 2);
        }else if(!tm.containsKey(x)){
            tm.put(x,2);
        }
    }
    for(int x: C){
        if(tm.containsKey(x) && tm.get(x)%10!=3){
            tm.put(x,tm.get(x)*10 + 3);
        }else if(!tm.containsKey(x)){
            tm.put(x,3);
        }
    }
    ArrayList<Integer> ans = new ArrayList<>();
    for(int x : tm.keySet()){
        if(tm.get(x)>10){
            ans.add(x);
        }
    }
    return ans;
}

}