Main idea: instead of loop through K lists and find the minimun val, use D&C to merge per 2 lists first so k lists turn into k/2 with avg length N/(k/2), then into k/4 and so on; time complexity: each time we traverse almost N nodes, but repeat this procedure...
[Read More]
1493. Longest Subarray of 1's After Deleting One Element
main idea: sliding window # time O(N) space O(1) class Solution: def longestSubarray(self, nums: List[int]) -> int: cnt1 = 0 res = 0 n = len(nums) l=r= 0 while r < n: if nums[r]==1: cnt1 += 1 res = max(cnt1,res) while r-l +1- cnt1 == 2: if nums[l] == 1:...
[Read More]
1021. Remove Outermost Parentheses
key question to solving this problem: how to identify if parentheses is outermost?? here we can see nested parentheses and seperate several nested parentheses. One feature of a parentheses is it always appear in pairs. So we may think of using counter to increment when encounting open parentheses and decrement...
[Read More]
88. Merge Sorted Array
main idea: there are two thoughts to start inserting number with correct order - 1. start with smallest 2. start with largest; but the problem with start with smallest is that once number from nums2 need to occupy non-empty position in nums1, it’s hard to reposition original number in nums1;...
[Read More]
981. Time Based Key-Value Store
built in binary search
```python
class TimeMap:
[Read More]