• + 0 comments

    Neat!

    That said, this definitely isn't O(1) auxiliary space. You allocate an array of length N

    It's also not O(n). It's O(N+K). If N = 3 and K = 1,000,000,000,000 that first for-loop is still gonna take a mighty long time (by comparison).