← Optiver Interview Insights

Optiver·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Optiver software engineer interview with a coding round that leaned heavily on binary search. The Koko Eating Bananas problem showed up, which is a classic LeetCode problem but still trips people up if you haven't thought carefully about what you're actually searching over.

Questions Asked (1)

Q1

Given n piles of bananas and h hours before the guards return, find the minimum eating speed k (bananas per hour) such that all piles can be finished in time. Each hour you pick one pile and eat up to k bananas from it.

Algorithms & Data Structures
Author's notes

The key insight is that you're not searching through the piles, you're binary searching on the speed itself.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

This is a classic optimization problem where we need to find the minimum valid eating speed. The key observation is that the feasibility of a speed k is monotonic: if k works, any larger speed also works. Therefore, we can use binary search on the answer, checking feasibility in O(n) time per candidate speed.

Pro tip: Always clarify edge cases and constraints upfront, such as whether h is at least the number of piles (otherwise it's impossible) and the range of pile sizes. This shows attention to detail and prevents incorrect assumptions.

1. Understand the problem and constraints

Restate the problem in your own words. Identify that each hour you choose one pile and eat up to k bananas, and you need to finish all piles within h hours. Note that h must be at least n (the number of piles), otherwise it's impossible.

2. Define the feasibility function

For a given speed k, compute the total hours needed as sum(ceil(pile / k)) for all piles. If this sum is <= h, then k is feasible.

3. Identify monotonicity and choose binary search

Observe that if speed k is feasible, any speed > k is also feasible. Thus, we can binary search for the minimum k in the range [1, max(piles)].

4. Implement binary search

Set low = 1, high = max(piles). While low < high, compute mid = (low + high) // 2. If feasible(mid), set high = mid; else set low = mid + 1. Return low as the minimum speed.

5. Analyze complexity and edge cases

Time complexity: O(n log m) where m is the maximum pile size. Space complexity: O(1). Handle edge cases: h < n (impossible), single pile, large h (speed 1 works).

Key Points to Mention

  • Monotonicity of the feasibility condition: if speed k works, any larger speed also works.
  • Binary search on the answer space from 1 to max(piles).
  • Feasibility check using ceiling division: hours = sum((pile + k - 1) // k).
  • Time complexity: O(n log m) where n is number of piles and m is max pile size.
  • Edge case: if h < n, it's impossible to finish all piles, so return -1 or handle appropriately.
  • Space complexity: O(1) extra space.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.