Implement PAVA spend-smoothing under no-borrowing constraint

Quick Overview

This question evaluates isotonic L2 regression, constrained quadratic optimization, and algorithmic implementation skills through a monotone spending plan with cumulative no-borrowing constraints, including designing and verifying an O(n) Pool-Adjacent-Violators-style routine and its empirical error/runtime.

Implement PAVA spend-smoothing under no-borrowing constraint

Company: Upstart

Role: Data Scientist

Category: Machine Learning

Difficulty: hard

Interview Round: Technical Screen

You are given a length-65 vector profit[1..65] of yearly discretionary income (can be treated as nonnegative real numbers). We want a spending plan s[1..65] that is as even as possible over time while not spending future money. Formally, solve: minimize Σ_{t=1..65} (s_t − profit_t)^2 subject to s_1 ≤ s_2 ≤ … ≤ s_65, s_t ≥ 0, and Σ_{i=1..t} s_i ≤ Σ_{i=1..t} profit_i for all t (no borrowing), with Σ_{t} s_t = Σ_{t} profit_t (no money left unallocated). 1) Show that the solution is the isotonic L2 regression of profit under a nondecreasing constraint (Pool-Adjacent-Violators Algorithm, PAVA) and explain why it respects no-borrowing when mass is only shifted forward. 2) Implement an O(n) PAVA (R or Python), returning s and the block structure. 3) Using set.seed(12345) and profit ~ rnorm(65, mean=1000, sd=100) (clip at 0 if needed), run your algorithm, report Σ(s_t − profit_t)^2, verify monotonicity, and demonstrate that cumulative spend never exceeds cumulative profit at any prefix. 4) Compare against a naive iterative averaging method (like repeatedly averaging decreasing runs) on both correctness and runtime.

Quick Answer: This question evaluates isotonic L2 regression, constrained quadratic optimization, and algorithmic implementation skills through a monotone spending plan with cumulative no-borrowing constraints, including designing and verifying an O(n) Pool-Adjacent-Violators-style routine and its empirical error/runtime.

|Home/Machine Learning/Upstart
Upstart logo
Upstart
Oct 13, 2025, 9:49 PM
hardData ScientistTechnical ScreenMachine Learning
11
0

Monotone Spending Plan via Isotonic L2 Regression (No-Borrowing)

Context: You observe yearly discretionary income profit[1..65] (nonnegative reals) and want a spending plan s[1..65] that is as even (nondecreasing) as possible over time while never spending future money. Formally, solve the quadratic program:

  • Minimize: Σ_{t=1}^{65} (s_t − profit_t)^2
  • Subject to:
    1. 0 ≤ s_1 ≤ s_2 ≤ … ≤ s_65 (smoothly nondecreasing spending)
    2. For all t: Σ_{i=1}^t s_i ≤ Σ_{i=1}^t profit_i (no borrowing)
    3. Σ_{t=1}^{65} s_t = Σ_{t=1}^{65} profit_t (no unallocated money)

Tasks:

  1. Show that the solution is the isotonic L2 regression of profit under the nondecreasing constraint (solved by the Pool-Adjacent-Violators Algorithm, PAVA), and explain why it respects no-borrowing when mass is only shifted forward.
  2. Implement an O(n) PAVA (R or Python) that returns s and the block structure.
  3. Using set.seed(12345) and profit ~ rnorm(65, mean=1000, sd=100) (clip at 0 if needed), run your algorithm, report Σ(s_t − profit_t)^2, verify monotonicity, and demonstrate that cumulative spend never exceeds cumulative profit at any prefix.
  4. Compare against a naive iterative averaging method (e.g., repeatedly averaging decreasing runs) on both correctness and runtime.
Loading comments...