Https://hack.codingblocks.com/app/practice/3/17/problem

https://hack.codingblocks.com/app/practice/3/17/problem
which approach use for that problem.
please give hint