Cumulative No-Intercept Regression Betas
Updated
Problem statement
You are given two matrices of the same shape, xRows and yRows. Each row holds returns for the same p assets, one asset per column. Column by column, the two matrices are paired.
The array batchSizes splits the rows into batches of rows that sit next to each other. Its first value is the number of rows in batch 0, the second is the number in batch 1, and so on. Every value is a positive integer, and they add up to the total number of rows.
Go through the batches in order. For each asset column j, pair each x value with the y value in the same position. After you add batch i, compute the cumulative no-intercept regression slope:
beta[j] = sum(x * y) / sum(x * x)
Both sums use every pair from batches 0 through i, inclusive.
Return one row of p slopes after each batch. An answer counts as correct if it is within an absolute or relative tolerance of 10^-6.
Function
cumulativeNoInterceptBetas(xRows: double[][], yRows: double[][], batchSizes: int[]) → double[][]Examples
Example 1
xRows = [[1.0,2.0],[2.0,1.0],[3.0,2.0]]yRows = [[2.0,1.0],[4.0,3.0],[6.0,2.0]]batchSizes = [2,1]return = [[2.0,1.0],[2.0,1.0]]After the first batch, asset 0 has slope (1*2 + 2*4) / (1^2 + 2^2) = 2. Asset 1 has slope (2*1 + 1*3) / (2^2 + 1^2) = 1. The second batch adds one row, and both slopes stay the same, so the two output rows match.
Example 2
xRows = [[1.0],[2.0],[1.0]]yRows = [[1.0],[2.0],[3.0]]batchSizes = [2,1]return = [[1.0],[1.3333333333333333]]After the first batch, sum(x * y) and sum(x * x) are both 5, so the slope is one. The second batch adds one more pair. Now sum(x * y) becomes 8 and sum(x * x) becomes 6, and the new slope is their ratio.
Constraints
1 <= xRows.length = yRows.length <= 2000001 <= batchSizes.length <= 200- Every batch size is positive, and their sum equals
xRows.length. 1 <= p <= 100, and every row has exactlypcolumns.- Every value is finite and has absolute value at most
10^6. - For every asset and every batch prefix, cumulative
sum(x*x)is positive.
More Citadel Phone Screen questions
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Evenly Schedule Vehicle InspectionsAmazon · PHONE SCREEN
- Implement Cross-Entropy LossOpenAI · PHONE SCREEN
- Add Signed Character ArraysByteDance · PHONE SCREEN
- Automation Pipeline, Part 2: Stage WorkersPlaid · PHONE SCREEN
- Reservoir Sampling with Recorded DrawsGoogle · PHONE SCREEN
- K-Means Delivery ZonesDoorDash · PHONE SCREEN · ONSITE INTERVIEW
- Token Bucket Request DecisionsDatadog · PHONE SCREEN
- Gradient Descent for Linear RegressionMicrosoft · PHONE SCREEN