You are viewing a single comment's thread. Return to all comments →
I've got the same algorithm implemented in C# but got runtime error when submitting it. I tried using either a Dictionary or my own array, but failed with both.
Any idea what could cause that problem?
I got the same problem.
Same here! Checked my code in LINQPad and it runs fine. Runtime error in HR.
you need to trim input :(
int arr = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), arrTemp => Convert.ToInt32(arrTemp));
I wasted an hour just to figure out this "Trim()" issue, obviously at least twice of the time taken to write the actual code.
The problem is, the bug is in the predefined part of the code! I wish HackerRank can have the predefined section refined more, or they shall not provide it at all. Also the test data itself is buggy. It shall not have the trailing whitespace though it is really common in the real world.
Yep, I have seen this issue also. When I copied the code locally in a new project and I also copied one of the test cases, the lines containing the array contained empty spaces at the end. So I have erased those lines at the end and it worked fine. But with a "buggy" input from hacker rank, there is no other option but to trim the input :-).
At least we figured it out :-).
this comment saved my day. Spent over 30 mins only debugging. :(
30 mins? I've been running my code for 2 f*cking hours trying to figure out where the problem in my code was
Are you kidding!! Same issue here.. after a good time trying to find out what was wrong with my code plus different implementations latter and this was the solution. I feel robbed of my time.
Same here in Kotlin. Calling trim() on cost array solved the issue.