Ad
  • Custom User Avatar

    If this kind of optimization is a bottle neck for you, then you shouln't be using Python anyway over something like C

  • Custom User Avatar

    Yes, theoretically. Your solution is the best one (and very cheap for memory). Now, practically, using loops with conditional branches is something slow in general, and builtin functions like split and min are optimized in Python, so the benefice if probably not relevant for the inputs that are tested here. It would be interesting to benchmark this.