posted 5 years 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.
There are three kinds of actuaries: those who can count, and those who can't.