**https://www.hackerearth.com/challenges/competitive/may-circuits-21/approximate/joystick-typing-eb25cf0f/** This contest is now over. I was stuck at this problem. After thinking a lot on this question, I am not able to figure in which direction I should proceed with this problem is it greedy or graph based question? Any hints are welcomed.