• + 1 comment

    Great solution!

    I don't think I could ever have come up with something like that!

    Is this considered a greedy solution?

    One thing I did change was to make the array size N+2 and skipped the bounds check.