Just got Optiver SDE Offer|This interview was really hardcore, but I hit all the brushing questions + underlying knowledge!

375 Views

Just got Optiver SDE offer, the mood is really excited. Reviewing it, the whole process was a snap, but the difficulty is really not comparable to the usual algorithmic side. If you are also rushing for quantitative / HFT positions, be sure to read this.

Just got Optiver SDE Offer|This interview was really hardcore, but I hit all the brushing questions + underlying knowledge!

Optiver SDE Real Questions Sharing

Question 1

Given an array of integers where each element represents the price of a given stock on day i, design an algorithm to find the maximum profit. You may complete Given an array of integers where each element represents the price of a given stock on day i, design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

Solution Analysis:

This is an advanced version of the typical "stock trading problem" and one of the most common applications of dynamic programming in interviews.
If only one trade is allowed, the problem is relatively simple: it is enough to find the minimum buy point and the maximum sell point. But when two trades are allowed, the key difficulty is - the two trades cannot overlap.

The violent solution is to traverse all the splitting points, split the array into left and right parts, compute the maximum profit separately and then add them up, with a time complexity of O(n²), which is obviously not efficient enough in the HFT interview scenario.

The optimal solution uses dynamic programming and requires only one traversal (O(n) time, O(1) space).
At its core, it maintains four state variables:

  • first_buy: Maximum profit after the first buy (initially negative infinity)
  • first_sell: Maximum profit after the first sale
  • second_buy: Maximum profit after the second purchase
  • second_sell: Maximum profit after the second sale

During the traversal process, the prices are updated with these four states each day:

first_buy = max(first_buy, -price)
first_sell = max(first_sell, first_buy + price)
second_buy = max(second_buy, first_sell - price)
second_sell = max(second_sell, second_buy + price)

The final answer is second_sell.
This type of question not only examines algorithmic thinking, but is a direct test of your ability to abstract state transfer logic.

Question 2

Implement Dijkstra's shortest-path algorithm for a weighted graph that's supplied as a nested-dictionary adjacency map. The function should return both the distance map and each node's previous pointer for path reconstruction.

Solution Analysis:

Dijkstra's algorithm is one of the most basic and practical algorithms in graph theory, but in high-frequency interviews, the focus is often not on "do you remember the algorithm", but on whether you can implement it efficiently.

Conventional implementations are easy to write as O(V²), and interviews would prefer to see you use the version with a priority queue (heapq), which reduces the complexity to O(E log V).

The realization steps are clear:

  1. Initialize the distance dictionary dist, all nodes are infinity and the source is 0;
  2. Initialize the precursor dictionary prev, record path back information;
  3. Use heapq stockpile (distance, node), popping the node with the smallest distance each time;
  4. For each neighboring node, if dist[u] + weight(u,v) < dist[v]Then it is updated and pressed into the heap.

The point is:

  • To explain why priority queues guarantee shortest path correctness;
  • Be able to write concise Python implementations;
  • If it's an HFT / Infra interview, you can discuss in passing how to hand-write heap structures in C++ to further optimize performance.

Question 3

How can you rotate an n x n matrix 90 degrees clockwise in-place, given only a basic Python list-of-lists representation?

Solution Analysis:

Keywords "In-place", i.e., no extra matrices are allowed and the space complexity must be O(1).
This question actually examines your understanding of matrix memory layout and order of operations.

The most common solution is in two steps:

  1. Transpose matrices first: swapping matrix[i][j] And matrix[j][i].;
  2. Reverse each row.

The combination of these two steps results in a 90° clockwise rotation.
If the interviewer presses further, asking "Is there a lower level, more atomic approach", he or she can askhierarchical rotation method:
Think of the matrix as consisting of concentric "layers" that rotate progressively from the outer layer to the inner layer, exchanging 4 elements at a time.

This idea not only demonstrates your flexible understanding of spatial manipulation, but also the organization of your thinking when writing algorithms.

Question 4

Explain why iterating through a 2D array column-wise is often significantly slower than iterating row-wise. Provide a C++ code example to illustrate and Provide a C++ code example to illustrate and explain the role of cache lines.

Solution Analysis:

This question is a common "Bottom-Level Performance Trap Question" for HFT / Systems interviews.
On the surface of the two-dimensional array traversal order problem, but actually examine whether you understand the principle of spatial localization of the CPU cache.

When the CPU reads memory data, it does not fetch just one variable, but a whole contiguous block of memory (called a cache line, usually 64 bytes).
suppose that... int It takes up 4 bytes, and a cache line can hold 16 consecutive ints.

When traversing by rows

for (int i = 0; i < N; i++)
  for (int j = 0; j < N; j++)
    sum += arr[i][j].

The accessed memory is continuous, the CPU loads a whole row at a time into the cache, and subsequent accesses have a very high hit rate and optimal performance.

When traversing by column:

for (int j = 0; j < N; j++)
  for (int i = 0; i < N; i++)
    sum += arr[i][j];

Jumping a whole line at a time leads to frequent cache misses and the need to constantly load a new cache line from the main memory, resulting in significant performance degradation.

In system or high-frequency trading positions, this type of question is examined behind the scenes:

Do you understand the design philosophy of "hardware at the service of algorithms".

The moment the offer came in.

Optiver's process is very fast, less than two weeks from OA to offer. It was not easy to get the offer. This interview made me realize the meaning of "code performance" again - it's not about writing code that runs, it's about writing code that is stable in microsecond scenarios.

So, if you are targeting high-frequency trading firms like Optiver, Jane Street, IMC, HRT, make sure you fill up the following modules:

  1. C++ underlying mechanisms (STL source code, memory model)
  2. Multithreading and locking mechanisms (especially condition variables)
  3. CPU cache, cache miss principle
  4. High Performance Algorithmic Thinking

One final thought.

For this type of interview, brushing up is really not enough. It is more like a comprehensive ability test: test you to understand the speed, code quality, underlying thinking and real-time responsiveness.

I also stepped on a lot of potholes while preparing - got stuck on complexity, locking mechanism, cache optimization. Then I hired a teaching assistant to accompany me remotely by voice, and it stabilized the pace of the interview too much. Especially that real-time voice reminder when stuck in the algorithmic tipping point is especially helpful for the rhythm.

If you are also preparing for Optiver, Jane Street, IMC, HRT, which are high performance/quantitative companies, consider getting a professional coaching team for mock interviews or voice assists. Like us. programhelp is a full remote assistance for HFT post, from OA to onsite can do without trace, real-time, rhythmic strong cooperation, many students rely on this successfully get offer.

author avatar
Jory Wang Amazon Senior Software Development Engineer
Amazon senior engineer, focusing on the research and development of infrastructure core systems, with rich practical experience in system scalability, reliability and cost optimization. Currently focusing on FAANG SDE interview coaching, helping 30+ candidates successfully obtain L5/L6 Offers within one year.
END