Well, not exactly O(n); but it's the same (technically, it is O(n) in average, it is not strictly O(n) because the numbers are not in order). How could this be O(n)? This would mean the result is returned after a constant number of operations, independent of the input. Obviously it is not. How many operations for n = 0, for n = 9? Each comparison is an operation.
ranks can't be changed
Thanks!
This comment is hidden because it contains spoiler information about the solution
Well, not exactly O(n); but it's the same (technically, it is O(n) in average, it is not strictly O(n) because the numbers are not in order). How could this be O(n)? This would mean the result is returned after a constant number of operations, independent of the input. Obviously it is not. How many operations for n = 0, for n = 9? Each comparison is an operation.
THis is O(n).