Ad
  • Custom User Avatar

    I disagree. An array of the same numbers is sorted, but it is ambiguous what direction it is sorted.

  • Custom User Avatar

    Thanks for the reply! You reminded me that time complexity does not depend on the number of traversals (i.e. O(n) vs. O(3n)). Seems that for a while I've been torturing myself in writing algorithmns XD

  • Custom User Avatar

    because it's simpler to write/debug (overall) and that won't change a thing about the actual speed (time complexity is the same). Actually, if you time your code, you'll see that this one is way faster (I didn't check, but that's a safe bet) because of python's interpreter (using builtins function is faster, most of the time).

    so, less code, more readable, less occasions to do a typo, less to maintain, meaningfull way to handle the problem (="accumulate meaningful data, then use them"). So, definitely the way to go. ;)

    cheers

  • Custom User Avatar

    I think there is a need to add description specification for the case where the input is an array of the same numbers.
    I personally take that as a "no" even though it fits both ascending and descending sorting definitions.

  • Custom User Avatar

    Your program will return "yes, ascending" for an array of same numbers while I think that should be a "no".
    Of course the description should've made it clear.

  • Custom User Avatar

    The program fails the test when n = 0.

  • Custom User Avatar

    Why do people traverse a list twice when traversing it once is enough?
    This is my first program in python - hoping to solve my confusion..

  • Custom User Avatar

    This is the greatest solution I have ever seen.