I was trynig a question of some hiring contest by esko on hackerearth (The contest is over). On first the question looked like some directed graph question. But I couldn't move forward. Can someone please think upon the solution.