Question bank › Sliding Window
Dsa Sliding Window Hard

Max Subsequence Sum Within Limit

Given an array of integers `nums` and an integer `limit`, find the maximum sum of a contiguous subsequence where the sum does not exceed `limit`. If no such subsequence exists, return 0. Input Format: The first line contains an integer `n`, the number of elements in the array. The second line contains `n` integers. The third line contains the limit integer. Output Format: Output a single integer representing the maximum sum of a valid subsequence. Example: Input: 5 1 2 3 4 5 10 Output: 10

Key concepts

sliding_windowarraygreedy

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.