Sum Of Minimum Liquidity Across All Contiguous Trading Windows

Last updated: November 29, 2026

Quick Overview

Given per-minute available liquidity values, compute the sum over every contiguous window of that window's minimum, modulo 1,000,000,007.

Point72
Coding & Algorithms
Software Engineer
Point72
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given per-minute available liquidity values, compute the sum over every contiguous window of that window's minimum, modulo 1,000,000,007.

This is the contribution-counting monotonic stack technique, framed as estimating worst-case fillable size across every possible execution window. Point72 onsite interviewers use it to see whether a candidate can move from an O(n^2) scan to O(n) by asking how many windows each element is the minimum of, with ties handled exactly once.

What the Interviewer Expects
  • Reframe as each element's contribution: value times number of windows where it is the minimum
  • Find previous strictly smaller and next smaller-or-equal indices with monotonic stacks
  • Use asymmetric tie handling so equal values are not double counted
  • Apply the modulus on accumulation
  • Reach O(n) time and O(n) memory
Key Topics to Cover
monotonic stack
contribution technique
combinatorial counting
modular arithmetic
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you compute the sum of window maximums, and then sum of (max minus min)?
  • How do you count only windows of length at most L?
  • Prove the tie-breaking rule counts each window exactly once.
  • Can you do it in one pass with a single stack?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Liquidity values are non-negative integers, n up to about 10^5, so the O(n^2) or O(n^3) brute force is too slow. Return the sum of minimums over all n(n+1)/2 windows, modulo 1e9+7....

High-Level Design

Flip the loop: instead of finding each window's minimum, count for each index i how many windows have vals[i] as their minimum. If the nearest index to the left with a smaller value is p and the neare...


Submit Your Answer
Markdown supported

Related Questions