used TreeSet as data structure in algo, huge Performance boost