Runtime error in code



link to question :

link to solution :

Getting runtime error on 5th test case .

Can’t figure out why?


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.


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.


Got AC using Map