• + 2 comments

    I solved it with recursion. Probably stupid but the problem is defined recursively so it was the first thing that popped in my mind. If you memoize the recursive calls it needn´t be terribly inefficient.