Not getting the code

Cannot understand the approach.Help with the code

@hemantomer1 hey check this code and dry run it pls:
https://ide.codingblocks.com/s/249796