Longest Payment Streak Allowing K Forgiven Late Payments

Last updated: November 29, 2026

Quick Overview

A borrower's repayment history is a string of 'P' (on time) and 'L' (late). Return the length of the longest contiguous stretch of months that contains at most k late payments.

Upstart
Coding & Algorithms
Software Engineer
Upstart
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


A borrower's repayment history is a string of 'P' (on time) and 'L' (late). Return the length of the longest contiguous stretch of months that contains at most k late payments.

Upstart services loans it originates, and servicing teams reason about repayment behavior windows for hardship programs and model features. The phone screen uses this to see whether you recognize a variable-size sliding window and can argue why it is linear.

What the Interviewer Expects
  • Identify the at-most-k sliding window pattern
  • Maintain a late count as the window grows and shrinks
  • Explain why each index enters and leaves once
  • Handle k = 0 and all-late histories
Key Topics to Cover
sliding window
two pointers
strings
counting
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
  • Return the start and end month of the best window as well.
  • How would you answer this for many different k values on the same history?
  • What if late payments have weights (30, 60, 90 days) and the budget is a total weight?
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: a string over {P, L} and a non-negative integer k. Output: the maximum window length whose count of L is at most k. An all-late history with k = 0 returns 0....

High-Level Design

Expand the right pointer one month at a time. When the number of late months inside the window exceeds k, move the left pointer forward until the window is valid again. The best valid width seen is th...


Submit Your Answer
Markdown supported