How to solve this runtime error? | SoloLearn: Learn to code for FREE!


How to solve this runtime error?

I was solving a coding competition question. I encountered this runtime error. This code gives output here but "runtime" or "wrong answer" while uploading the solution 🤦🏻‍♂️. I used hashintnext() but it doesn't work. How to solve this inorder to pass the testcases? For better explanation of the doubt :

12/4/2020 3:08:38 PM

Aditya(Less active)

7 Answers

New Answer


Thanks I got my answer.. But still wondering for a solution with while loop and postfix as -- operater .. But Minho made that to clear! Thanks everyone :)


Yes but I wanted with -- operator 😆 Thanks a lot C-MOON ,Minho 🇰🇷 I appreciate your help ))


Ooh my bad🤦🏻‍♂️ thanks


Ahh that's true but the program needs my understanding ? it may be a case I go wrong..but idk🤷‍♂️ Please see this question


You have forgotten decrement the h -= 1; Besides I did small changes for clear coding:



Too few inputs. You need 1(for h)+N(for i, number of times the while loop run) inputs. You can avoid this NoSuchElementException by moving 'i=sc.nextInt()' outside of the while loop, but this time the loop runs forever, because the value of h is unchanged.