Stack Solution ```python Definition for singly-linked list. class ListNode: def init(self, val=0, next=None): self.val = val self.next = next class Solution: def nextLargerNodes(self, head: ListNode) -> List[int]: “”” tc O(N) sc O(N) idx 0 1 2 3 4 5 6 7 val 1,7,5,1,9,2,5,1 ans 7 9 9 9 0 5...
[Read More]
962. Maximum Width Ramp
Solution1: Mono Stack + Binary Search
```python
[Read More]
1856. Maximum Subarray Min-Product
Solution: Presum + mono Stack class Solution: def maxSumMinProduct(self, A: List[int]) -> int: """ tc O(N) sc O(N) main idea: assume any A[i] is smallest, extend its max range to get largest presum 1. get left bound: for A[i], within i:0, the first index j so that A[j] < A[i]...
[Read More]
632. Smallest Range Covering Elements from K Lists
class Solution: def smallestRange(self, A: List[List[int]]) -> List[int]: """ tc O(NlgK) sc O(K) PQ : (diff, i,j) main idea: find res: max-min so that res is smallest => get min,max as close as possible 1. put smallest val of each row into pq. tuple (val, i,0) i:row number, 0:right most...
[Read More]
1606. Find Servers That Handled Most Number of Requests
class Solution: def busiestServers(self, k: int, arrival: List[int], load: List[int]) -> List[int]: """ k server each server 1 req / time for req[i]: (1) if len(avail) <1 : req.drop() (2) if (i%k) server available, assign req else: (3) (i%k) next available server => loop server id from status map ?...
[Read More]