```python
Definition for a binary tree node.
class TreeNode:
def init(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
[Read More]
1481. Least Number of Unique Integers after K Removals
```python class Solution: def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: “”” 1. cnt 2. sort by occurance, delete least occurance with k 3. return len(d) + (k < 0 ) O(NlgN) space O(N) “”” d = {} for num in arr: d[num] = d.get(num,0) + 1 kv = sorted(list(d.items()),key...
[Read More]
LC452. Minimum Number of Arrows to Burst Balloons
```python class Solution: def findMinArrowShots(self, A: List[List[int]]) -> int: “”” time O(NlgN) space O(1) 0. check edge case if points is empty 1. sort by end point 2. cache 1st end, start looping with 2nd 3. current start ptr > end s cnt +1 note here if end with start...
[Read More]
25. Reverse Nodes in k-Group
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseKGroup(self, head: ListNode, k: int) -> ListNode: """ tc O(N) sc O(N//K) recursively loop per k LList segment, and meanwhile reverse each k LList keep the...
[Read More]
92. Reverse Linked List II
```python Definition for singly-linked list. class ListNode: def init(self, val=0, next=None): self.val = val self.next = next class Solution: # time O(N) space O(N) def reverseBetween(self, head: ListNode, m: int, n: int) -> ListNode: self.successor = None def reverseN(head,n): # base case(termination condition): when n == 1, recursion has reached...
[Read More]