You are viewing a single comment's thread. Return to all comments →
What's the input of the test case that's failing?
Test cases 1,2and4. Input of test case 1 being:
9 8 6 7 3 5 4 1 2
Hi. The problem is with this line of your code:
It evaluates the expression inside the () from left to right. So it first tries to do ar[k], where k is -1 and it gets an Index Out of Bounds Exception. To fix it, you can change it to
while(k >= 0 && ar[k] > temp)
Now, it will check for k >= 0 first. If it's not greater than 0, the next expression (to the right of &&) will not evaluate.
This is called short circuit evaluation
Man you are awesome. You made my day. I didn't know about this, thank you. Thank you so much :-)
thanku so much !!