But don't forget the array can be as big as 10^7. Try to print 10M ints to your console, and measure the time. It reminds me of a similar exercise at HackerRank, where I had to print about 10M strings to the console. Whatever I tried, I kept having these TimeOut errors. At last, I changed the complete given inputroutine. Here you use a split and parseInt (java speak) to get your array, See if you can replace that with something faster.
If the input will always be a number you dont even have to int.parse. you can just compare the characters
posted 1 year ago
Don't forget that 2 < 100, but "2" > "100".
First improvement: how many times do you 'int.Parse' an element of the array?
If that doesn't help: you are calling Console.Write for every element in the array. What if you write them to (in Java speak) a StringBuilder first, and print that when you're done?
Another way I considered was to compare two strings first by looking at their size, and then doing the parsing, if necessary. But the elements are between 1 and 1000, so in many cases you still have to use parsing. I haven't tested it, but it may be worth trying.