Runtime error in code

codeforces
runtime-error

#1

link to question : http://codeforces.com/contest/817/problem/B

link to solution : http://codeforces.com/contest/817/submission/27807533

Getting runtime error on 5th test case .

Can’t figure out why?


#2

You are storing frequencies in the arr2 and array elements can be upto 10^9.So you can’t use an array to store frequencies and instead of arrays you should use map to store frequencies.

here is my accepted solution and if you have any doubt,please comment.
http://codeforces.com/contest/817/submission/27798017


#3

Since the input array has elements of the order 10^9, you invoke index out of bounds by writing arr2[arr**]++.

In the case where you get the runtime error, each arr* is 10^9 and the size of arr2 is 10^5. Hence the index out of bounds.


#4

Got AC using Map
Thanks!!