Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    Why is this answer getting so many best practice votes? Surely since sqrt returns a floating point value, with which arithmatic is limited in precision, which could cause false answers. It would also risk undefined behaviour due to integer overflow with larger n values as squaresquare (square_rootsquare_root) reaches the max value for an int.
    Calculating square roots is also much slower than other integer operations so its not really an efficient approach. Am i mistaken here or missing something?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution