Reported September 2026
Two Sigmaprefix sum

Online No-Intercept Linear Regression

Reported by candidates from Two Sigma's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Two Sigma OA. Under 2s to a working solution.
Founder's read

Two Sigma's September 2026 OA reportedly includes a streaming regression problem, and the data structure it hinges on is just two running doubles. That's the whole thing. You get batches of x and y values, and after each batch you return the cumulative slope for a no-intercept fit y = kx. It looks like stats homework, but it's a prefix-sum problem in disguise. If you've got an OA invite for this week, expect a short solve with a couple of floating-point traps. StealthCoder runs invisibly on your screen as a safety net if you blank on the live assessment.

The problem

You are fitting a no-intercept linear-regression model y = kx to observations that arrive in batches. The x-values and y-values are provided as matching matrices xBatches and yBatches; row i contains the paired observations in batch i.
Process the batches in order. Maintain the cumulative values
numerator = sum(x * y)
denominator = sum(x^2)
over every observation seen so far. After each complete batch, the current slope is k = numerator / denominator.
Return an array containing the cumulative slope after every batch, in input order. Update the two running sums incrementally; do not rescan observations from earlier batches.

Function
onlineNoInterceptSlopes(xBatches: double[][], yBatches: double[][]) → double[]

Examples
Example 1
xBatches = [[1.0,2.0],[3.0]]
yBatches = [[2.0,4.0],[9.0]]
return = [2.0,2.642857142857143]
After the first batch, the running numerator is 1 * 2 + 2 * 4 = 10 and the denominator is 1^2 + 2^2 = 5, so the slope is 2. The second batch adds 27 to the numerator and 9 to the denominator, giving 37 / 14.
Example 2
xBatches = [[-2.0,1.0],[0.0,4.0]]
yBatches = [[4.0,1.0],[5.0,8.0]]
return = [-1.4,1.1904761904761905]
The first batch gives (-2 * 4 + 1 * 1) / ((-2)^2 + 1^2) = -7 / 5 = -1.4. The sample with x = 0 changes neither running sum. After adding (4, 8), the cumulative slope is 25 / 21.

Constraints
1 <= xBatches.length = yBatches.length
Every batch is non-empty, and xBatches[i].length = yBatches[i].length.
The total number of observations across all batches is at most 10^5.
All coordinates are finite double-precision values.
After every batch, the cumulative sum(x^2) is positive.
Answers within an absolute or relative error of 10^-6 are accepted.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: keep two accumulators, numerator as the sum of x*y and denominator as the sum of x^2. Loop through batches in order, add each batch's contributions, then push numerator / denominator to the result. One pass over at most 10^5 observations, O(n) time, O(number of batches) output. No rescanning earlier batches, which the statement forbids anyway. Pitfalls are small but real. Use doubles, not ints, for both sums. Don't divide until the batch is fully processed, since the slope only counts after a complete batch. Zero x values are harmless. Negative values work fine because the numerator can go negative while the denominator can't. The constraints guarantee the denominator is positive after each batch, so skip the zero-division guard worries. Precision tolerance is 10^-6, so plain accumulation is fine. If you freeze mid-assessment, StealthCoder is the hedge that hands you this loop in seconds.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Online No-Intercept Linear Regression cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Two Sigma's OA.

Two Sigma reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Online No-Intercept Linear Regression FAQ

How hard is the Two Sigma online no-intercept linear regression question really?+

Easy once you see it. It's two running sums and a division per batch. The difficulty is the wrapper text about regression, which scares people who haven't seen the formula. The statement hands you the formula, so you just implement it.

What's the trick to solving it?+

Keep numerator and denominator as persistent doubles across batches. For each batch, loop through the paired x and y values, add x*y and x*x, then append numerator / denominator to the output. Never recompute from earlier batches.

Do I need to worry about division by zero?+

The constraints guarantee the cumulative sum of x squared is positive after every batch. So you can divide directly after each batch. Don't divide mid-batch, since the slope is only defined after a complete batch.

Is floating-point precision a risk here?+

Not much. The checker accepts absolute or relative error up to 10^-6, and plain double accumulation over 10^5 values stays well within that. Use double everywhere and avoid integer casts or early rounding.

How do I prepare for this in 48 hours?+

Practice running-total problems and streaming aggregation, where you update state incrementally instead of rescanning. Write this one from scratch once, then test with the negative-value and zero-x examples. That covers nearly every edge case it has.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Two Sigma.

OA at Two Sigma?
Invisible during screen share
Get it