I tried using heap but did not work Can anyone share the approach?. P.S. The challenge for me is over now. So i am not doing it to cheat. I just want to know the approach for this problem. I tried for 2 hours but could not come with correct answer.