Pair of roses RUN ERROR

https://hack.codingblocks.com/contests/c/474/696

I’m getting the output correct in coding clocks ide… but run error while submitting …!!
https://ide.codingblocks.com/#/s/13507

1 Like

You have not initialized p2 and q2. Thus, a case might arise that if cnt==1 and the min1 was updated only once, therefore p2 and q2 are pointing to arbitrary index of array.
e.g.:
Try your code’s output for input:
1
4
6 6 6 6
I have modified your code
https://ide.codingblocks.com/#/s/13556

1 Like

thank you so much…So we get run error when we’re trying print a variable which not initialised…!
is there any other case when this RUN ERROR appears ?!!

No, it was the case that p2 was holding a garbage value and then you tried to access arr[p2] whose value was not known.
RUN TIME ERROR occurs because of different reasons.

1 Like