Days Until a Savings Balance Rises Above Today's Level

Last updated: November 29, 2026

Quick Overview

Given end-of-day balances for a 360 Performance Savings account, return for each day how many days pass until the balance is strictly higher, or 0 if it never rises above that day's level again.

Capital One
Coding & Algorithms
Data Engineer
Capital One
November 29, 2026
Data Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given end-of-day balances for a 360 Performance Savings account, return for each day how many days pass until the balance is strictly higher, or 0 if it never rises above that day's level again.

Savings growth features in the Capital One app summarize how long it takes customers to rebuild after a withdrawal. The interviewer is checking the monotonic stack pattern: recognizing next-greater-element, maintaining the stack invariant and explaining why the solution is linear.

What the Interviewer Expects
  • Identify the next-greater-element structure
  • Keep a stack of indices with non-increasing balances
  • Resolve each waiting index when a higher balance arrives
  • Leave unresolved days at 0
  • Explain the amortized O(n) argument
Key Topics to Cover
Monotonic stack
Next greater element
Amortized analysis
Arrays
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 instead return the number of days until the balance first falls below today's level?
  • How would you answer this for a stream where days arrive one at a time?
  • How would you compute the longest stretch where the balance stayed at or below a given day's value?
  • What if equal balances should also count as recovered?
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
  • Input: list of daily balances (integers in cents).
  • Output: list of the same length; entry i is the gap to the first later day with a strictly greater balance, else 0.
  • Equal balances do not count...
High-Level Design

Brute force scans forward from every day, O(n^2) on a long flat or falling history. Instead, sweep left to right with a stack of indices still waiting for a higher balance. The stack's balances are no...


Submit Your Answer
Markdown supported