```python class Solution: def removeDuplicates(self, nums: List[int]) -> int: “”” time O(N) space O(1) step1: edge case–> nums is empty or nums less than 2 step2: create start ptr, to track unique number so far; create cnt = 1 step3: iterate nums, find number different from start ptr number, ptr...
[Read More]
LC969 Pancake Sorting
class Solution: def pancakeSort(self, A: List[int]) -> List[int]: def swp(sub,k): i = 0 mid = k //2 while i < mid: sub[i], sub[k-i-1] = sub[k-i-1], sub[i] i += 1 res = [] val_sort = len(A) while val_sort > 0 : idx = A.index(val_sort) if idx != val_sort -1: if idx...
[Read More]
LC553 Largest Component Size by Common Factor
class Solution: # time O(NlgM) where M is factors and numers . space O(M+N) N for map, M for UF uf = UF(max_val) #step1, attribute num in A to all groups that lead by factors for num in A: factor_max = int(sqrt(num)) for fac in range(2,factor_max+1): if num % fac...
[Read More]
LC436 Find Right Interval
class Solution: def findRightInterval(self, intervals: List[List[int]]) -> List[int]: """ step1, check edge case if length is less than 2, if yes, return -1 based on length step2, initialize res array filled with -1 and length is same as intervals step3, use tuple (interval) as key, index as val to save...
[Read More]
LC20 Valid Parentheses
```python
[Read More]