Shorter variant


def maxMin(lst):
  for i in range(0, len(lst), 2):
    lst.insert(i, lst.pop())
  return lst
1 Like

Hi Dennis,

Thank you for you feedback.

We’ll review your proposal and get back to you as soon as possible.

Arqam Rehan

Hey Dennis,

This is a great solution as it is very Pythonic and takes constant space. However, the only reservation I have is that it seems that insert() takes O(n) in the average case. and since insert occurs n/2 times, the time complexity comes out to be O(n^2) which isn’t optimal. A caveat though: Python has not officially declared the time complexity of the insert() function, the wiki page says that it is in O(n). So you might be able to use this fact to get away with this solution in an interview!

Best Regards,
Ayesha Basit | Technical Content Developer

1 Like