We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I agree with @farhan_tanvir_u1, the way you have it coded. The second stack will be checked to the end, once the first stack has been totally depleted, and the second stack holds all the numbers, it will not stop.
Suggest adding an additional check for sum <= x. Once i = 0 && sum > x, you can stop checking the second stack.
Game of Two Stacks
You are viewing a single comment's thread. Return to all comments →
I agree with @farhan_tanvir_u1, the way you have it coded. The second stack will be checked to the end, once the first stack has been totally depleted, and the second stack holds all the numbers, it will not stop. Suggest adding an additional check for sum <= x. Once i = 0 && sum > x, you can stop checking the second stack.