You are viewing a single comment's thread. Return to all comments →
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. :(