You are not logged in. Please login at to post your questions!


Runtime error in code

link to question :

link to solution :

Getting runtime error on 5th test case .

Can't figure out why?

asked 16 Jun '17, 15:24

chunky_2808's gravatar image

accept rate: 4%

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.


answered 16 Jun '17, 15:35

hruday968's gravatar image

accept rate: 14%

edited 16 Jun '17, 15:42


Got AC using Map Thanks!!

(16 Jun '17, 15:44) chunky_28083★

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

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


answered 16 Jun '17, 15:39

zeeshan_ju's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 16 Jun '17, 15:24

question was seen: 325 times

last updated: 16 Jun '17, 15:44