TODO
TODO
TODO
Needs some major spaghetti cleanup. Can't reason about correctness.
This is still O(2^h) not O(h).
Can't figure out a solution better than O(n lg k) ~ O (n lg n) and O(k) space.
Is there a solution faster than O(n^2)? What would a dynamic programming solution look like? Can this be implemented using semi-rings?