whats wrong in code plzz comment it out
Https://ide.codingblocks.com/s/258743
check now
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
https://www.hackerrank.com/challenges/game-of-two-stacks/problem?h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen it is the link of the question am solving on hackerrank along this am attaching the solution of it but i dont know why its not shwoing correct answer will u please check it this is ths link ----->https://ide.codingblocks.com/s/277630
@Aditya-Kushwaha-914550392281281 the condition should be like this
x = 10 is the original value (in this test case), so x > 10 will be false and the code will not be executed.
but mam still its not giving right output
@Aditya-Kushwaha-914550392281281 do a dry run of the code for the given input to figure out the logical mistake, give it some time, that’s how you learn. I’ll be happy to help if you cant figure it out
mam i dry run it but still cant fighure out where am wrong the output is 4 and my output is 5
@Aditya-Kushwaha-914550392281281 here is the code https://ide.codingblocks.com/s/278053
- You are first increasing i, (or j), and then changing the value of x, that is wrong. You need to change the value of x according to the current value of i or j
- even when you are subtracting, you need to make sure the value does not become negative BEFORE you make the change, to avoid a case like for eg
x = 4, and a[i] = 10. You do x-a[i] and x becomes -6, the while loop will break, but x is negative, this transaction should not have happened in the first place.
I hope I have cleared all your doubts. Please mark the doubt as resolved if that’s the case.