Ad
  • Custom User Avatar

    This solution is O(N) in time. The "in-place" solution you are mentioning is O(N/2) which boils down to O(N) too, since 1/2 is just a constant factor.

    The true difference between them lies in their space complexities. This one is O(N) in space, although it is simply mutating the input. But the "in-place" is O(1) in space because it does not use any auxiliary memory.

    I still prefer this solution though, as you only need to user lower() once and it is very readable overall. Also, memory has become extremely cheap nowadays and it shouldn't be that much of a problem.

  • Custom User Avatar

    I had a very similar solution to you. I really like pop because it returns the removed value. It was perfect for this kata. Cheers