Binary Search (Brute Force solution) class Solution: def minDays(self, A: List[int], m: int, k: int) -> int: """ constrains: (1) len(A) >= m*k (2) adjacent k flowers => after t, there are m*k flowers and each bunch has k adjecent flowers tc O(Nlg(maxA)) sc O(1) """ def cntBouquet(t:int,A:List[int])->int: flowers =...
[Read More]
1231. Divide Chocolate
class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: """ x : min sweeetness I will get range [min(A), sum(A)] X range is [min(A),avg(A)] assuming x = l + (r-l+1)//2, count shares >= K, if cnt < K: r = mid -1 else: l = mid """ """tc O(Nlg(agv(A)))...
[Read More]
1011. Capacity To Ship Packages Within D Days
```python class Solution: def shipWithinDays(self, A: List[int], D: int) -> int: “"”tc O(Nlg(sum(A))) sc O(1) find min capacity to carry all weights in A and total time cost <= D => estimate capacity = ceil ((total weight) /D ) constrains: each package a is not splitable => left pointer need...
[Read More]
1793. Maximum Score of a Good Subarray
class Solution: def maximumScore(self, A: List[int], k: int) -> int: """ tc O(N) sc O(1) main idea: (greedy)based on condition i <= k <= j, k must exist within subarray, initial distance between i,j is 1 => two pointer problem, get the neighbour with larger value """ #idx 0 1...
[Read More]
1537. Get the Maximum Score
```python class Solution: def maxSum(self, A: List[int], B: List[int]) -> int: “”” tc O(N+M) sc O(1) [wrong thought] I thought it will be a dfs + memo get max accumutive sum, but since there are only two choices at each common node, we can use two ptr to simplify the...
[Read More]