1018. Binary Prefix Divisible By 5

```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 class Solution: def flipMatchVoyage(self, root: TreeNode, voyage: List[int]) -> List[int]: “”” main idea: global idx indicates next integer in voyage; if current node is None: means we... [Read More]
Tags: Array

331. Verify Preorder Serialization of a Binary Tree

```python class Solution: def isValidSerialization(self, preorder: str) -> bool: “”” tc O(N) sc O(N) 1. remove , and save it into arr 2. loop through arr and check current node if is None 3. if yes, diff + 2 else diff -1 9 -1/ -1 3 2 -1 /-1 \... [Read More]
Tags: Stack

774. Minimize Max Distance to Gas Station

Binary Search Solution class Solution: def minmaxGasDist(self, A: List[int], k: int) -> float: """tc O(Nlg(max(A))) 1. set left, right boundry, get candidate max distance 2. count amount of gas stations to be inserted. If > K , d is to small; """ n = len(A) l , r = 0,... [Read More]

875. Koko Eating Bananas

```python class Solution: def minEatingSpeed(self, A: List[int], h: int) -> int: “"”tc O(Nlg(max(A)) sc O(1) main idea: goal is to minimize k s.t. at speed of k/ hour can finish sum(A); condition: (1)time cost at pile i—> ceil(A[i]/k) (2) k <= A[i] and len(A) <= h ==> l,r = 1,... [Read More]