Ad
  • Custom User Avatar

    I was going to say something similar, it's much more efficient to leverage a heap. Not nearly as pretty tho

  • Custom User Avatar

    You really only want to use recursion when there's a big benifit to it, like in dynamic programming where you are caching the results of subproblems. It's also really good for generating permutations, lists, variations, etc. Using recursion on a problem like this is actually a bad idea though and is the easiest way to end up with a stack overflow on what is a pretty simple problem.

  • Custom User Avatar

    While loop, recursion can blow up your stack on large data sets

  • Custom User Avatar

    I believe you're trying to do something on an empty list that can't be done on an empty list. I had the same error, but don't remember exactly what I did to fix it.