InterviewLegend

Onsite Algorithms: Stock Profit, Scale-Out & Line Math

Alex Chen40 min readGuide updated
In this lesson
  • Solve the stock profit problem in one pass, then the unlimited-trades version
  • Split the stock scan across threads or machines with mergeable chunk summaries
  • Find y = a*x + b at four distinct indices by matching two hash maps
  • Explain the O(n^2) pair split out loud and guard the products against overflow

Most Zoox technical screens are trivia plus a class design problem. The onsite is where the classic algorithms show up. Zoox's own internship page says its coding questions look like the exercises on platforms like LeetCode, and full-time loops match that. One problem family keeps coming back. Best time to buy and sell stock turns up in onsites from 2021 through 2026, and a mid-level candidate in September 2025 called it the hardest question of the day.

What sets the Zoox version apart is the scale-out at the end. Once your single pass works, interviewers have asked you to multithread it (2024), or to split data that won't fit in memory across N machines and write the pseudo code (2023). This lesson works that family first, then the y = a*x + b task that shared a round with it. Older problems from 2018 to 2024 are in Older Practice Problems.

The Zoox angle
Plan for the second half of the round. The base problems here are short, and reported rounds keep going after the first green run. Be ready to parallelize, say what each machine sends back, and name the 64-bit overflow before the interviewer does.

What the Zoox onsite coding round looks like

Expect a shared online editor where your code has to run. Most teams let you pick C++ or Python. Go was accepted in an October 2026 loop. Teams that ship code onto the vehicle may switch you to C++ for the onsite even after a Python screen, as one 2024 candidate found out. An October 2026 onsite opened its first round with language trivia and then a coding problem, so a few minutes of quick questions in your language may come first.

The solutions below are Python. The editor also has C++, Java, Go, JavaScript and Ruby starters for every problem. If your team might move you to C++, write the stock and line problems in C++ at least once. The line task is where overflow bites: a product of two values near a billion doesn't fit in a 32-bit int.

Each problem here comes down to one small summary. Stock profit keeps the lowest price so far, and its parallel version carries a lowest price, a highest price and a best profit per chunk. For the line task you store every product a*x in a map, keyed to the pair of indices that made it.

Best time to buy and sell stock, then scale it out

Candidates describe it from a July 2021 front-end loop through a September 2025 mid-level onsite, and it was still being asked in May and June 2026. The 2025 candidate got the classic version: daily prices, one buy and one sell, maximum profit. Their example was 4, 3, 2, 6, 1, 7, which gives 6. An L3 loop in April 2024 asked the unlimited-trades version next, then multithreading for both.

The scale-out ask runs from 2021 to 2024. A 2021 loop kept "distribute a problem across multiple hosts" as a backup question. In October 2023 a senior C++ candidate, who didn't name the base problem, was told the data doesn't fit in memory and asked to split the work across N machines in pseudo code. They wrote multithreaded C++ instead and heard back "not senior enough". A November 2023 round titled "Algorithm in pseudo code" asked how to deploy the stock answer on many machines.

1

Best Time to Buy and Sell Stock

EasySignature problem
Problem
You get prices, where prices[i] is the price of one stock on day i. Choose one day to buy and a later day to sell.

Return the largest profit you can make. If no trade makes money, return 0. A list with fewer than two prices also returns 0.
Inputprices = [4,3,2,6,1,7]Output6

Buy at 1 on day 4 and sell at 7 on day 5. Buying at 2 and selling at 6 only makes 4.

How this uses the pattern

Walk the prices once. Keep the lowest price seen so far, and at each day compare selling today against that low.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Best Time to Buy and Sell Stock

Loading...
Click "Run" to execute your code
The Zoox angle
The one-pass answer takes two minutes, and Zoox interviewers know it. Get it working, say it's O(n) time and O(1) space, and expect the next ask straight away. Recent loops asked for the unlimited-trades version, then threads, then many machines. Write the loop so its state is small and easy to name, because that state is what each machine will send back.
Take it further
Split it across N machines. Each machine scans its own range of days and returns three numbers: its lowest price, its highest price and the best profit inside the range. Two neighbouring summaries merge with best = max(left best, right best, right highest minus left lowest). The merge is associative, so you can reduce in a tree. The walkthrough has both this and the unlimited-trades version.

Four values with y = a*x + b at distinct indices

In an April 2024 L3 loop, the stock questions were followed by "a math question related to y = mx+c" in the same round. A November 2023 loop gives the shape and the intended answer. You find values that satisfy y = ax + b, and the best solution builds a map of y - b, another of a*x, and looks for equal values. A May 2026 technical screen asked something similar: four values at distinct indices, with cases where none exist and products too wide for 32 bits.

The version below is something like the direct reading: one array, four different positions, does any choice satisfy the equation. It's the same kind of pair-matching as 4Sum, so practicing this covers both.

2

Four Values on a Line

MediumCommonly asked
Problem
You get an integer list nums. Decide whether there are four different indices i, j, k and l such that nums[i] == nums[j] * nums[k] + nums[l].

Read it as y = a*x + b, with y, a, x and b each taken from a different position. Values may repeat in the list, but an index can be used only once. Return true if such a choice exists and false otherwise.
Inputnums = [2,3,7,1]Outputtrue

7 = 2 * 3 + 1, using indices 2, 0, 1 and 3.

How this uses the pattern

Rearrange to y - b = a * x. Store every a * x pair product in a map, then walk every (y, b) pair and look up y - b.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Four Values on a Line

Loading...
Click "Run" to execute your code
The Zoox angle
In 2024 it came straight after the stock question, and the two-map answer is the one a 2023 interviewer was after. Brute force over four indices is O(n^4). Splitting the equation into two pair sides gets it to O(n^2) pairs, and saying that rearrangement out loud early is worth more than the code. The wide-integer warning matters in C++ and Java, where a*x needs a 64-bit type.
Take it further
Return the witness, then handle a skewed map. Returning the four indices is a small change: keep the pair lists and return the first disjoint match. The harder question is a list full of repeats, where one product value holds thousands of pairs that all share an index with the (y, b) pair. Cap each list at a few pairs that use different indices, since only a pair that avoids both i and l can match.

Common questions

What coding questions does Zoox ask at the onsite?

Best time to buy and sell stock is the one candidates report most, from 2021 through 2026. It comes with follow-ups that multithread it or split it across machines. The y = a*x + b task followed it in the same round in a 2024 loop and came up again in a May 2026 technical screen.

Is the Zoox coding interview LeetCode style?

The onsite mostly is. Zoox's internship page compares its questions to LeetCode exercises, and the problems above match. The technical screen is different for many teams. It's usually language trivia followed by a practical class design problem that has to run, covered in the screen problems lesson.

Which language should I use?

C++ or Python for most teams, and Go was accepted in an October 2026 loop. Vehicle teams may ask for C++ at the onsite even after a Python screen (2024). Language trivia follows whatever you pick, so choose the one you can answer quick questions about.

How should I practice these?

Code each base problem from a blank file in under ten minutes, then spend the rest of the session on the follow-ups. Explain the stock chunk summary out loud as if you were writing the pseudo code for N machines. Write the line task once in C++ with 64-bit products.

Key Takeaways

  • ✓Stock profit is the recurring Zoox onsite algorithm. Finish the one-pass answer fast and save time for the scale-out.
  • ✓For N machines, each chunk returns its lowest, highest and best. The merge adds the cross trade, right highest minus left lowest.
  • ✓Rewrite y = a*x + b as y - b = a*x, map pair products to index pairs, and check that all four indices differ.
Zoox interview guide

Know what Zoox asks before you walk in.

21 coding · 4 system design · 30 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

Class Design: Roller Coaster Scoring & Airline PricingHad your Zoox interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.