← Optiver Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Optiver software engineer interview with three algorithm mini-problems back to back. The problems ranged from a sliding puzzle to stream processing to string deduplication, and each one had a follow-up angle that made the naive solution not quite enough.

Questions Asked (3)

Q1

Given an N-block sliding puzzle on a 2D grid with one empty cell, find the minimum number of moves to reach a target arrangement, or return -1 if it's impossible. Walk through your state encoding and whether you'd use BFS or A* with an admissible heuristic.

Algorithms & Data Structures
Author's notes

I started with BFS and encoded the board as a flattened tuple so it could go into a visited set.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by encoding the puzzle state as a string or integer (e.g., tuple of tile positions) and use BFS to guarantee the shortest path in an unweighted graph. For larger N, discuss A* with an admissible heuristic like Manhattan distance or linear conflict to prune the search space, and handle unsolvability by checking parity of inversions.

Pro tip: Optiver values both correctness and efficiency: mention that BFS is simple but may be infeasible for large N, while A* with a strong heuristic is practical. Also, explicitly state how you detect unsolvable configurations (e.g., inversion parity) to avoid infinite search.

1. State Representation

Encode the board as a tuple of integers (0 for empty) or a string; this allows hashing for visited sets and easy neighbor generation.

2. Graph Search Choice

Use BFS for guaranteed shortest path in unweighted graph; for larger N, switch to A* with an admissible heuristic (e.g., Manhattan distance) to reduce explored states.

3. Heuristic Design

Define an admissible heuristic like sum of Manhattan distances of each tile to its goal position; optionally add linear conflict for stronger pruning while maintaining admissibility.

4. Solvability Check

Before search, check if the puzzle is solvable by computing inversion parity (and blank row parity for odd/even grid sizes); if unsolvable, return -1 immediately.

5. Complexity & Optimization

Analyze time/space complexity (O(b^d) for BFS, O(b^d) worst-case for A* but often much less); mention bidirectional BFS or IDA* as alternatives for memory constraints.

Key Points to Mention

  • State encoding using tuples/strings for hashing and visited set.
  • BFS guarantees shortest path but may be memory-intensive; A* with admissible heuristic is more efficient for larger puzzles.
  • Manhattan distance as an admissible heuristic; linear conflict for stronger pruning.
  • Solvability condition: inversion parity (and blank row parity for odd/even grid sizes).
  • Time and space complexity: BFS O(b^d), A* depends on heuristic quality.
  • Handling of -1 for unsolvable cases and edge cases (e.g., already solved, N=1).

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

Q2

You're reading a token stream where each token is either a directional arrow or a non-negative integer. Output 1 if the token is an arrow matching the previous arrow's direction, or if the token is an odd integer. Otherwise output 0. Do it in O(1) time and O(1) space per token.

Algorithms & Data Structures
Author's notes

Easiest of the three for me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the token types and the exact condition, then design a state machine that processes each token in constant time and space. Maintain only the previous arrow direction and output the required bit based on the current token. Emphasize that no additional data structures are needed.

Pro tip: Explicitly state that you only need to remember the last arrow direction (or a sentinel if none) and that integer parity is checked on the fly, demonstrating true O(1) space. This shows you understand the problem's constraints and can avoid overcomplicating.

1. Clarify token types and conditions

Confirm that tokens are either arrows (e.g., ←, →, ↑, ↓) or non-negative integers, and that the output is 1 if the token is an arrow matching the previous arrow's direction, or if it's an odd integer; otherwise 0.

2. Identify necessary state

Determine that the only state needed is the direction of the last arrow seen (or a sentinel if none). No other history is required.

3. Design per-token logic

For each token: if it's an arrow, compare its direction to the stored previous arrow direction; output 1 if they match, else 0. Then update the stored direction. If it's an integer, output 1 if odd, else 0 (and leave the stored arrow direction unchanged).

4. Handle edge cases

Consider the first token: if it's an arrow, there is no previous arrow, so output 0 (unless the problem specifies otherwise). If it's an integer, just check parity.

5. Analyze complexity

Confirm that each token is processed with a constant number of operations and that only a single variable (the previous arrow direction) is stored, achieving O(1) time and space per token.

Key Points to Mention

  • State machine approach with minimal state
  • Constant time and space per token
  • Handling of first arrow (no previous direction)
  • Parity check for integers (odd/even)
  • Updating state only when an arrow is encountered
  • Avoiding unnecessary data structures

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

Q3

Given up to a million strings (potentially Unicode), return all strings that appear more than once along with their frequencies. Compare hash-based vs external sort approaches, address memory constraints, and discuss how you'd handle strings that are semantically equivalent but encoded differently.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

This one went longer than expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the constraints (memory, disk, time) and then propose a hash-based solution using a hash map with string keys, discussing memory optimizations like storing hashes instead of full strings. Compare with external sort by sorting chunks and merging, and address Unicode normalization for semantic equivalence. Conclude with a recommendation based on trade-offs.

Pro tip: Mention that you would first normalize Unicode strings (e.g., NFC) to handle encoding differences, and consider using a cryptographic hash with a low collision probability to reduce memory usage, but be prepared to handle collisions by storing full strings only for candidates.

1. Clarify Requirements and Constraints

Ask about memory limits, whether the data fits in memory, time constraints, and if strings are semantically equivalent when encoded differently. This shows you consider practical aspects before diving into solutions.

2. Propose Hash-Based Approach

Describe using a hash map (e.g., Python dict) to count frequencies, iterating through strings. Discuss memory usage: storing full strings may be too large, so consider storing hashes (e.g., 64-bit) and only storing full strings for collisions or when count > 1.

3. Propose External Sort Approach

Explain sorting strings externally: divide into chunks that fit in memory, sort each chunk, write to disk, then merge sorted chunks while counting duplicates. This uses less memory but more disk I/O and time.

4. Compare Trade-offs

Compare hash-based (fast, memory-heavy) vs external sort (slower, memory-light). Discuss when to use each: if memory is sufficient, hash map is simpler; if not, external sort. Mention hybrid approaches like partitioning by hash.

5. Address Unicode Normalization

Explain that strings may be semantically equivalent but encoded differently (e.g., NFC vs NFD). Propose normalizing all strings to a canonical form (e.g., NFC) before processing to ensure correct duplicate detection.

Key Points to Mention

  • Hash map with string keys: O(n) time, O(n) memory; can optimize by storing hashes and handling collisions.
  • External sort: O(n log n) time, O(1) memory but high disk I/O; suitable for large datasets.
  • Unicode normalization: use NFC or NFD to canonicalize strings; consider case folding and locale-specific rules.
  • Memory constraints: if strings are large, storing full strings may exceed memory; use hashing or external sort.
  • Trade-offs: hash-based is faster but memory-intensive; external sort is slower but scalable.
  • Hybrid approach: partition strings by hash into buckets that fit in memory, then process each bucket.

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