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

+12

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 : https://ide.geeksforgeeks.org/CnlU50OSYk https://code.sololearn.com/cwzt3XhB8117/?ref=app

12/4/2020 3:08:38 PM

Aditya(Less active)

7 Answers

New Answer

+16

Thanks I got my answer.. https://code.sololearn.com/cqinvQE3G6Is/?ref=app https://code.sololearn.com/cfC0AFyeBlVk/?ref=app But still wondering for a solution with while loop and postfix as -- operater .. But Minho made that to clear! Thanks everyone :)

+15

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

+14

Ooh my bad🤦🏻‍♂️ thanks

+13

Ahh that's true but the program needs it..by my understanding ? it may be a case I go wrong..but idk🤷‍♂️ http://arena.siesgst.ac.in/contest/NOV20/problem/NOV20C Please see this question

+6

You have forgotten decrement the h -= 1; Besides I did small changes for clear coding: https://code.sololearn.com/cLmAeW1Nf1Cj/?ref=app

+3

https://code.sololearn.com/cAn3xu2mSGeb/?ref=app

+2

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.