Ad
  • Custom User Avatar

    @ozann This function is extremely slow even for inputs of 30,000 (20.3s on my computer).
    The language has little to do with it. This same thing coded in C would be thousands of times slower than a good Python solution even for an array of 30,000 elements.

  • Custom User Avatar

    Problem description doesn't mention a time constraint nor does it say the program should be "efficient". There's a simple task, and this is the most hassle-free, readable, and Pythonic way of attaining it. If you care so much about performance, you should stop programming in Python altogether.