JangoBoogaloo / LeetCodeExcercise

1 stars 0 forks source link

Define Boundary, Guess the answer and binary search it #317

Open JangoBoogaloo opened 1 month ago

JangoBoogaloo commented 1 month ago

Concept

Define the upper/lower bound of the answer, try binary search guess. Have a method to verify if the guess result bigger or smaller than the criteria

Question Set

https://leetcode.com/problems/minimum-time-to-repair-cars/ <-- this one is gold!!! https://leetcode.com/problems/minimum-speed-to-arrive-on-time/ https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ https://leetcode.com/problems/koko-eating-bananas/ https://leetcode.com/problems/maximum-candies-allocated-to-k-children/ https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/ https://leetcode.com/problems/sell-diminishing-valued-colored-balls/ https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag/ https://leetcode.com/problems/divide-chocolate/ <-- this one is gold!!! (hard)

JangoBoogaloo commented 1 month ago

image

JangoBoogaloo commented 1 month ago

Find Smallest Element

mid = (left + right) //2 left = mid + 1 right = mid

Find Largest Element

mid = (left + right+1) //2 right = mid - 1 left = mid

JangoBoogaloo commented 1 month ago

❗ Need a better Binary Search formula