Java Solution..... priority Queue works here.....though it uses linear space and nlogn time


#1

Comment body goes here.