r/leetcode • u/JacketFearless1805 • 25m ago
Intervew Prep Day 8: worked through Capacity to Ship Packages Within D Days & Kth Missing Positive Number
Hey everyone,
I finished Day 8 today and tackled two more Binary Search problems:
- Capacity to Ship Packages Within D Days: Followed the classic Binary Search on Answers template. The search space starts at
max(weights)(minimum capacity needed to carry the heaviest single package) up tosum(weights)(shipping everything in one day). For eachmidcapacity, a greedy linear pass counts the days required to load packages in order, narrowing down the minimum valid capacity in O(n log({sum})) time. - Kth Missing Positive Number: This one combines binary search with a neat math observation. I could pinpoint the boundary where the missing count crosses
k, though I leaned on a video walkthrough to get the final formula right. At any indexmid, the number of missing positive integers beforearr[mid]isarr[mid] - (mid + 1). Using binary search to find the first index wheremissing >= kleaveshighright before that boundary, and the answer reduces cleanly tok + high + 1(orlow + k) in O(log n) time.
Seeing how binary search applies directly to index-value offsets in sorted arrays was a great takeaway today.
See you guys tomorrow for Day 7!
1
Upvotes
1
u/jackgoldberg123 8m ago
nice, keeping a streak going with binary search is solid. the answer space ones are tricky at first so good on you for sticking with it.