Fantastic. I was trying to create this simple O(n) O(n) solution. Only when you see it do you realise how simple it is. Kicking myself, as I was almost there twice but deleted and went down other avenues.
Great work.
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.
Doesnt this solution conduct two passes? - one for splitting, and one for finding the min? So for larger strings this would be less efficient than a single for loop.
its a c++17 feature, so is more efficient. eg for larger vector sizes. It can run both accumulation and reduction in parrallel meaning its optimized for multicore systems. Although for this eg the differences are miniscule.
This comment is hidden because it contains spoiler information about the solution
If this kind of optimization is a bottle neck for you, then you shouln't be using Python anyway over something like C
Fantastic. I was trying to create this simple O(n) O(n) solution. Only when you see it do you realise how simple it is. Kicking myself, as I was almost there twice but deleted and went down other avenues.
Great work.
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
andmin
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.Doesnt this solution conduct two passes? - one for splitting, and one for finding the min? So for larger strings this would be less efficient than a single for loop.
its a c++17 feature, so is more efficient. eg for larger vector sizes. It can run both accumulation and reduction in parrallel meaning its optimized for multicore systems. Although for this eg the differences are miniscule.
This comment is hidden because it contains spoiler information about the solution
agree.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution