Katkat

Solve Banana Speed and Interval Merge

GoogleSoftware Engineer · Technical Screen

Last updated

Solve minimum eating speed and merge intervals for a new graduate phone screen. The solution covers binary search on answer, integer ceiling division, monotonic feasibility, interval sorting, overlap merging, correctness, complexity, and edge cases.

During two technical phone screens for a new graduate software engineering role, the candidate was asked to solve two coding problems: minimum eating speed and merging overlapping intervals.

Constraints & Assumptions

  • Provide clear algorithms, correctness reasoning, complexity, and edge cases.
  • For minimum eating speed, each hour can be spent on only one pile.
  • For interval merging, intervals overlap when the next start is less than or equal to the current merged end.
  • Use sorted or binary-search approaches where appropriate.

Clarifying Questions to Ask

  • Are piles and h always positive?
  • Is h at least the number of piles?
  • Are interval endpoints inclusive?
  • Can intervals be empty or unsorted?

Part 1 - Minimum Eating Speed

Given piles and h, return the minimum integer speed k such that all piles can be eaten within h hours.

What This Part Should Cover

  • Binary search on answer from 1 to max(piles).
  • Feasibility function using sum of ceil(pile / k).
  • Why feasibility is monotonic.
  • Complexity and edge cases.

Part 2 - Merge Overlapping Intervals

Given intervals [start, end], merge all overlapping intervals and return non-overlapping intervals sorted by start.

What This Part Should Cover

  • Sort by start.
  • Maintain current merged interval.
  • Extend on overlap, otherwise append and start a new interval.
  • Complexity and edge cases.

Follow-up questions

  • How would you avoid floating-point division in the banana problem?
  • What if `h` is smaller than the number of piles?
  • How do you merge touching intervals like `[1,3]` and `[3,5]`?
  • How would you handle streaming intervals?