Need for help

Need idea for this problem.Any algorithm necessary for solving this?
Problem link:Programming Problems and Competitions :: HackerRank