Exist or not(Challenges: Hashing)

It is showing run-error in second test case,but correct answer in other two.https://ide.codingblocks.com/s/101126

Hello,
Runtime error can occur due to the following reasons:

  1. Invalid memory access during run-time.
  2. Accessing linked list nodes that do not exist.
  3. Dividing by zero.
  4. Large allocation of memory together/Large Static Memory Allocation.
  5. Making a silly mistake.

What you have done is silly mistake.
Don’t worry, everybody does that. This will reduce over time.

So, coming back to your code.
There is a problem when you are declaring b[q] in your code.
Actually, you have not entered the value of q, but you are passing q as size of b[] array.
This is causing runtime error.

Solution:
cin>>q;
long long int b[q];

Hope, this would help.
Give a like, if you are satisfied.

1 Like