← Optiver Interview Insights

Optiver·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Optiver Data Scientist interview with a pretty involved algorithmic puzzle about rearranging apartments across floors with minimum moves. The question had multiple layers and I wasn't fully prepared for how deep they wanted to go on the optimality proof.

Questions Asked (4)

Q1

You have apartments distributed across floors 1 through 4 in some initial arrangement, and a target arrangement. Each move repositions one apartment to a different floor, subject to the target's per-floor counts. Design an algorithm that transforms the initial state into the target using the minimum number of moves, and argue why it's optimal.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I went with a matching approach where you count mismatches per floor and figure out the minimum swaps needed globally rather than floor by floor.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a transportation problem where each floor has a supply (initial count) and demand (target count). The minimum number of moves equals the total surplus (or deficit) across all floors, which can be computed by summing the positive differences between initial and target counts. Argue optimality by showing each move can reduce the total surplus by at most 1, and a greedy algorithm achieves this bound.

Pro tip: Emphasize that the problem reduces to a simple counting argument, not a complex assignment, and that the minimum moves is independent of which specific apartments move—only the per-floor counts matter. This shows you can abstract away unnecessary details.

1. Define the state and moves

Represent the initial and target arrangements as counts per floor. A move takes one apartment from a floor with surplus to a floor with deficit.

2. Compute surplus and deficit

For each floor, calculate the difference between initial and target counts. Positive differences are surpluses, negative are deficits.

3. Derive the minimum moves

The minimum number of moves equals the sum of all positive differences (or equivalently, the sum of all deficits). This is the total number of apartments that must be relocated.

4. Argue optimality

Show that each move can reduce the total surplus by at most 1, so at least S moves are needed. Then describe a greedy algorithm that always moves from a surplus floor to a deficit floor, achieving exactly S moves.

5. Discuss implementation and edge cases

Mention that the algorithm runs in O(F) time where F is the number of floors, and handles cases where initial and target counts are already equal (zero moves).

Key Points to Mention

  • The problem is equivalent to a transportation problem with unit costs.
  • Minimum moves = total surplus = sum of positive (initial - target) differences.
  • Each move can fix at most one unit of surplus, so the lower bound is tight.
  • Greedy algorithm: repeatedly move an apartment from any surplus floor to any deficit floor.
  • The specific apartments moved do not matter; only the counts per floor are relevant.
  • Time complexity is O(F) where F is the number of floors (here, 4).

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

Q2

What is the time and space complexity of your algorithm?

Algorithms & Data Structures
Author's notes

Straightforward enough since the number of floors is fixed at 4.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly stating the time and space complexity using Big O notation, then explain how you derived them by analyzing the algorithm's loops, recursion, and data structures. Relate the complexity to the problem constraints and discuss any trade-offs you made between time and space.

Pro tip: At Optiver, interviewers value practical optimization: mention how your complexity scales with input size and whether it meets the performance requirements for real-time trading systems. If applicable, note that you considered constant factors and low-level optimizations, as these matter in latency-sensitive environments.

1. State the complexities

Clearly state the time and space complexity in Big O notation, e.g., O(n log n) time and O(n) space.

2. Explain the derivation

Walk through the algorithm step-by-step, identifying loops, recursive calls, and data structures that contribute to the complexity.

3. Analyze best, average, and worst cases

Discuss how the complexity varies with input and mention the worst-case scenario, as it's often the most critical.

4. Discuss trade-offs and optimizations

Explain any trade-offs between time and space and whether you could improve one at the expense of the other.

5. Relate to problem constraints

Connect the complexity to the problem's input size and performance requirements, showing awareness of practical implications.

Key Points to Mention

  • Big O notation and its formal definition
  • How to analyze loops (nested loops multiply, sequential loops add)
  • Recursion and the Master Theorem for divide-and-conquer algorithms
  • Space complexity includes auxiliary space and input space
  • Amortized analysis for dynamic arrays and hash tables
  • Trade-offs between time and space (e.g., caching, memoization)

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

Q3

Is the greedy strategy of fixing Floor 1 first and then proceeding through Floors 2 to 4 always optimal? Either prove it or find a counterexample.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I got tripped up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem setup: what exactly is being optimized (e.g., total time, cost) and what constraints exist. Then, analyze whether the greedy choice of fixing Floor 1 first is always part of an optimal solution by testing small cases or constructing a counterexample. If a counterexample exists, present it clearly; otherwise, outline a proof using exchange arguments or dynamic programming.

Pro tip: In interviews, it's often more impressive to find a counterexample than to attempt a complex proof. Start by testing simple cases (e.g., 2 floors) to see if the greedy choice fails, and if it does, generalize the counterexample.

1. Clarify the problem

Restate the problem to ensure you understand the objective and constraints. Ask clarifying questions about what 'fixing' entails, the costs involved, and whether floors can be fixed in any order.

2. Define optimality

Define what 'optimal' means in this context (e.g., minimizing total time, cost, or number of operations). This will guide your analysis.

3. Test small cases

Consider the smallest non-trivial cases (e.g., 2 or 3 floors) and compute the optimal solution by brute force. Compare with the greedy strategy to see if it matches.

4. Attempt proof or counterexample

If the greedy strategy seems optimal, try to prove it using an exchange argument or induction. If it fails, construct a counterexample and explain why it invalidates the greedy approach.

5. Conclude and discuss implications

State your conclusion clearly. If a counterexample exists, discuss what it implies about the greedy strategy and suggest alternative approaches (e.g., dynamic programming).

Key Points to Mention

  • Greedy algorithms are not always optimal; they require proof of correctness.
  • Exchange argument: show that any optimal solution can be transformed to include the greedy choice without worsening the objective.
  • Counterexample construction: identify a small instance where greedy fails and generalize.
  • Dynamic programming as a fallback for optimization problems with overlapping subproblems.
  • The importance of clarifying assumptions in ambiguous interview questions.
  • Time complexity trade-offs between greedy and optimal solutions.

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

Q4

If there are multiple ways to reach the minimum number of moves, how would you output one valid sequence of moves?

Algorithms & Data Structures
Author's notes

Felt like the easier part after the earlier stuff.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain that you would use BFS to find the shortest path and store parent pointers for each visited state. Then, to output one valid sequence, backtrack from the goal state to the start using any stored parent, ensuring the sequence is valid and minimal.

Pro tip: Mention that you can break ties arbitrarily (e.g., by move order) but must ensure consistency; also note that storing all parents is unnecessary if only one sequence is needed, which saves memory.

1. Model the problem as a graph

Define states as nodes and moves as edges. This abstraction helps apply standard shortest-path algorithms.

2. Run BFS to find shortest distances

Use BFS from the start state to compute the minimum number of moves to each state, including the goal.

3. Store parent pointers during BFS

When visiting a new state, record the predecessor state and the move that led to it. For multiple optimal paths, any valid predecessor works.

4. Backtrack from goal to start

Starting at the goal, follow parent pointers until the start state, collecting moves in reverse order.

5. Reverse and output the sequence

Reverse the collected moves to get the sequence from start to goal, which is one valid minimal sequence.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs.
  • Parent pointers allow reconstruction of one optimal path.
  • Multiple optimal paths exist; any valid parent choice yields a valid sequence.
  • Tie-breaking can be arbitrary but must be consistent.
  • Memory optimization: store only one parent per state.
  • Time complexity: O(V+E) for BFS plus O(L) for backtracking, where L is path length.

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