Given an integer array, write a program that determines if it is sorted in ascending order.
Remember that this is a code trolling question.
I am looking for most interesting ways that people come up with.
The answer with most upvotes wins.
This question is inspired by a 'creative' solution that a candidate gave me in an interview :)
The 'creative' solution was something like this:
Because for a sorted array
- all the elements on the left side of any element must be smaller
- all the elements on the right side of any element must be bigger
Therefore, run a main loop for all elements and check the above two conditions by running two nested loops inside the main one (one for left side and one for right side)
I was shocked!!.