Time: O(N); two for loop iterating NSpace: O(N); HashMap contains N elements at mostTime: O(nlogn); sortingSpace: O(1)
I don't need to track the sequence of numbers....just need to track max frequency and frequency of each numbervar FreqStack = function() { this.top
push -> peek: check if pop element is equal if yes -> pop, continueif no -> pushbreak ifpop index is equal to length of pushed aray andstack is not em
Time: O(N)Space: O(1)but code is too longTime: O(nlogn), 100 times slower than 1st try
Time: O(N)Space: O(N)from leetcode "SlovakUnion"The idea is a(x + y) <=> ax + ayTIME: O(N)Space: O(1)
with whilewith recursionTime: O(logY)Space: O(1), only cnt;
Time: O(N),Space: O(1), some language String is a char\[]
Time: O(N)Space: O(N), how to make this to O(1)?O(1) space
Constance space means no matter how n increases the space ur code using stays equal.