Burglar_anu's blog

By Burglar_anu, history, 3 years ago, In English

1831B - Array merging

When i submit it is showing 'out of bounds' error but the other solution is getting accepted the only difference is that i have used two one dimensional array and he have used one two dimensional array.

Error submission: 242771431 Accepted submission: 242771679

Please help, why am i getting the error?

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
3 years ago, hide # |
← Rev. 2  
Vote: I like it +1 Vote: I do not like it

According to my logic , your second solution should also be with 'out of bounds' because in the

for (int i = 0; i < n; i++) 
 if (a[i] == a[i - 1])
     cnt++
 else
     cnt = 1;

you are going beyond the index of the variable i = -1 which does not exist.

Here is your corrected solution, I increased the length of the array and also added 2 if

if (i == 0) cnt = 1 

corrected solution