• Custom User Avatar

    True. I read somewhere though that Big O notation specifically focuses on the worst case scenario. So I'd assume when dealing with conditionals you have to take whichever branch that will result in the largest runtime, meaning you have to include the splice. Not sure about that though I'll have to look it up.

    See - 2. if-then-else statements:
    http://pages.cs.wisc.edu/~vernon/cs367/notes/3.COMPLEXITY.html#application

  • Custom User Avatar

    Is the second solution really O(n) time, You do have a splice - O(n), nested inside a reduce loop - O(n), nested inside a filter loop - O(n), wouldn't that make it O(n * m * m)? I'm thinking the first solution is faster since it's only 2 levels nested, just the sort stuff inside the filter loop O(n * nlogn)