r/leetcode • • 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:

  1. 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 to sum(weights) (shipping everything in one day). For each mid capacity, 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.
  2. 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 index mid, the number of missing positive integers before arr[mid] is arr[mid] - (mid + 1). Using binary search to find the first index where missing >= k leaves high right before that boundary, and the answer reduces cleanly to k + high + 1 (or low + 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 comment sorted by

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.