Open in TheBrain

Space Complexity: O(n)