Can anyone find the error in this problem this was the 3rd problem in june long challenge

Firstly, link the problem and your submission instead of posting a screenshot.

Coming to your solution, changing the continue; to break; should solve the issue. When you’re continuing after declaring the flag as 0, the flag can subsequently become 1, and you’ll be printing a “YES” when the answer is actually “NO”.

Another thing that I notice is that the difference logic is not quite right. You are supposed to subtract the change that chef gives from minchange. By adding a positive value to minchange everytime, it just keeps growing and Chef would never run out of coins.

Take the test case 5\;10\;5\;10\;5\;10\;10 for i = 5 your minchange = 30 and diff = 0. Here you’re trying to print “YES”, but Chef has actually run out of coins, and cannot give change to the last person!

1 Like

thanks for help buddy it is really awesome explanation