• + 0 comments

    This solution is actually O(n) space: you use actual array of (n+1) elements. And time is O(n+m)

    This task can be solved with O(m log m) time and O(m) space. For this task, it's better.