Ad
  • Default User Avatar

    That would work. However, it is a solution inefficient in terms of memory, as you are creating another list having the same size of the original.
    There are better ways, as seen in other people's solutions.

  • Custom User Avatar

    +1 to this comment - a whole bunch of the top-rated answers actually fail on this check, so it would be a great idea to add this in to the test cases.

  • Custom User Avatar

    Technically correct; however, the original list was mutated. Try deep-copying the list that was passed in, then work with those values instead. :)