time O(N) space O(N)
```python
[Read More]
239. Sliding Window Maximum
```python from collections import deque class Monoque: def init(self): self.q = deque() def push(self,num): # ensure numbers in queue is decreasing, pop off smaller numbers before push curren number in while self.q and self.q[-1] < num: self.q.pop() self.q.append(num) def max(self): # since queue is monotical decreasing, q bottom is biggest...
[Read More]
1283. Find the Smallest Divisor Given a Threshold
```python class Solution: def smallestDivisor(self, A: List[int], threshold: int) -> int: “”” tc O(Nlg(max(A))) question sum up : find a smallest divisor to make sum of division at each element in array <= threashold constrains: (1)each division round up => >= 1 => max divisor is max number in array...
[Read More]
1217. Minimum Cost to Move Chips to The Same
main idea: there is no cost to move even steps, so to weigh coins number in odd and even position. Whichever has the less ammount will move to the opposite position. ```python time O(N) space O(1) class Solution: def minCostToMoveChips(self, position: List[int]) -> int: odd = 0 even = 0...
[Read More]
64. Minimum Path Sum
class Solution: def minPathSum(self, grid: List[List[int]]) -> int: col = len(grid[0]) row = len(grid) dp = [[0 for _ in range(col)] for _ in range(row)] dp[0][0] = grid[0][0] for i in range(row): for j in range(col): if j == 0 and i == 0: continue dp[i][j] = min(dp[i][j-1] if j-1...
[Read More]