Failing on test case 2 only, don't know why

Here’ the link to the code: https://ide.codingblocks.com/s/164293
I’m not able to figure out what case I’m missing.

Your approach is not correct , forward + baackward is not the answer , it just work for the given sample test.
Try some random example and you will get the optimal way.

Can you please provide me a test case…I know something is wrong in my code but not able to figure out. A test case would make things clear.

You can write any random numbers.
If you use forward and backward , there will be overcounting.

Thanks. Understood, got AC.