You might have encountered this puzzle at several places. Including in WhatsApp and other social media which is circulated in the following manner:
You will find many discussions on the web on solving this which ends up in the answer 148. We can also obtain the result by writing a program and asking machine to solve it.
A C program for this along with detailed comments can be found in following github link. Have a look: