← Optiver Interview Insights

Optiver·Software Engineer·Onsite - Coding / Algorithms·Senior

SeniorPrefer not to say
May 2026

Summary

Ninety-minute coding gauntlet at Optiver with three back-to-back problems spanning DP, heap design, and NP-hard approximation. The breadth was a lot to cover in the time given, and the third problem in particular felt like it was testing whether you'd panic or just commit to something reasonable.

Questions Asked (3)

Q1

Given an integer array and a threshold T, count the number of non-empty subsequences with sum at most T. Explain why brute force fails, justify your approach (DP or otherwise), and give complexity analysis.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The brute force explanation part tripped me up more than the actual DP.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (array size, value ranges, threshold) and explaining why brute force enumeration of all 2^n subsequences is infeasible. Then present a dynamic programming approach that counts subsequences by sum, using a DP table or map, and analyze its time and space complexity. Finally, discuss potential optimizations or trade-offs based on constraints.

Pro tip: Mention that if the threshold is small, a DP over sums is efficient; if the array is large but values are small, a meet-in-the-middle approach can be used. Also, note that counting subsequences (not subsets) means order doesn't matter, but each element can be included or not, so it's equivalent to subsets.

1. Clarify constraints and define subsequence

Ask about array size, value ranges (including negatives), and threshold magnitude. Confirm that a subsequence is any subset of indices in order, but since order doesn't affect sum, it's equivalent to subsets.

2. Explain why brute force fails

Brute force would enumerate all 2^n non-empty subsequences, which is exponential and infeasible for n > ~20. Even with pruning, worst-case remains exponential.

3. Propose a DP approach

Use DP where dp[s] = number of subsequences with sum s. Initialize dp[0]=1 (empty subsequence). For each element x, update dp[s] += dp[s-x] for s from T down to x (if x positive) or adjust bounds for negatives. Finally, sum dp[s] for s=1..T.

4. Analyze complexity and discuss trade-offs

Time O(n*T), space O(T). If T is large, use a hash map to store only reachable sums, but worst-case still O(n*T). Mention meet-in-the-middle for large n and small T, or if values are small, use generating functions.

5. Handle edge cases and conclude

Address negative numbers (shift sums or use map), empty array, and threshold <=0. Summarize that DP is optimal for moderate T, and mention alternative approaches if constraints differ.

Key Points to Mention

  • Exponential brute force (2^n) and why it's impractical.
  • Dynamic programming over sums: dp[s] = count of subsequences summing to s.
  • Time complexity O(n*T) and space O(T) for the basic DP.
  • Handling negative numbers by shifting sums or using a hash map.
  • Meet-in-the-middle as an alternative for large n and small T.
  • Counting non-empty subsequences: subtract 1 for the empty subsequence if included.

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

Q2

Implement a job scheduler supporting INSERT, POP (smallest priority with stable tie-breaking), and DECREASE_KEY operations, all guaranteed O(log n), using a binary heap. Handle invalid and duplicate operations gracefully.

Algorithms & Data StructuresSystem Design
Author's notes

DECREASE_KEY is always the annoying one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: INSERT adds a job with a priority, POP removes and returns the job with the smallest priority, and DECREASE_KEY lowers a job's priority. Use a binary min-heap with an auxiliary hash map from job ID to heap index to achieve O(log n) for all operations, and handle edge cases like duplicate IDs, invalid IDs, and empty heap.

Pro tip: Emphasize stable tie-breaking by storing an insertion sequence number with each job and comparing it when priorities are equal; this shows attention to detail and avoids subtle bugs.

1. Clarify requirements and edge cases

Ask about expected input sizes, whether job IDs are unique, and what should happen on invalid operations (e.g., DECREASE_KEY on non-existent ID, POP on empty heap).

2. Design data structures

Propose a binary min-heap where each element stores (priority, insertion_order, job_id) and a hash map mapping job_id to its current index in the heap.

3. Implement core operations

For INSERT: add to heap end, update map, bubble up. For POP: swap root with last, remove last, update map, bubble down. For DECREASE_KEY: update priority, bubble up.

4. Handle invalid and duplicate operations

Check if job_id exists in map for DECREASE_KEY; if not, return error. For INSERT, if job_id already exists, either reject or update (clarify). For POP on empty heap, return null or throw exception.

5. Analyze complexity and test

Confirm all operations are O(log n) due to heap height. Walk through examples including ties and edge cases to verify correctness.

Key Points to Mention

  • Binary heap implementation with array representation
  • Hash map for O(1) access to job's heap index
  • Stable tie-breaking using insertion sequence number
  • Handling duplicate job IDs (reject or update)
  • Handling invalid operations (e.g., DECREASE_KEY on missing ID)
  • Time complexity analysis: O(log n) for INSERT, POP, DECREASE_KEY

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

Q3

For selecting k items from n to minimize total score given item weights and pairwise penalties (an NP-hard problem), propose and implement a greedy or simulated annealing heuristic. Cover initialization, stopping criteria, and how you'd measure approximation quality against a baseline.

Algorithms & Data StructuresTechnical Trade-offsAdaptability & Ambiguity
Author's notes

This one was rough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and defining the objective function. Then propose a greedy heuristic for a quick baseline, followed by simulated annealing for improvement. Discuss initialization, stopping criteria, and how to measure approximation quality against the greedy baseline and possibly an exact solver for small instances.

Pro tip: Emphasize the trade-off between solution quality and runtime, and suggest using the greedy solution as the initial state for simulated annealing to speed up convergence. Also, mention the importance of tuning parameters like temperature and cooling schedule based on problem size.

1. Clarify the problem and define the objective

Restate the problem: select k items from n to minimize total score = sum of weights + sum of pairwise penalties. Confirm that penalties are symmetric and only apply to selected pairs.

2. Propose a greedy heuristic

Design a greedy algorithm: start with an empty set, iteratively add the item that minimizes the increase in total score (weight + penalties with already selected items) until k items are selected. This provides a fast baseline.

3. Design simulated annealing

Define state representation (set of k items), neighborhood moves (swap one selected item with an unselected one), initial temperature, cooling schedule, and stopping criteria (e.g., max iterations, no improvement for X iterations, or temperature below threshold).

4. Measure approximation quality

Compare simulated annealing result to greedy baseline and, for small n, to an exact solution (e.g., brute force or integer programming). Report relative improvement and runtime trade-offs.

5. Discuss implementation and trade-offs

Outline how to implement efficiently (e.g., incremental score updates, data structures) and discuss trade-offs between solution quality, runtime, and parameter tuning.

Key Points to Mention

  • Objective function: sum of weights + sum of pairwise penalties for selected items.
  • Greedy initialization: iteratively add item minimizing marginal increase in score.
  • Simulated annealing: state representation, neighborhood moves (swap), acceptance probability, cooling schedule.
  • Stopping criteria: max iterations, temperature threshold, no improvement for X iterations.
  • Approximation quality: compare to greedy baseline and exact solution for small instances.
  • Parameter tuning: initial temperature, cooling rate, number of iterations per temperature.

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