Dsa
Two Pointers
Easy
Longest Movie Sequence
Given a list of movie lengths, you are to find the length of the longest contiguous subarray where the sum of the movie lengths does not exceed a given maximum length.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of movies.
- The second line contains n space-separated integers representing the movie lengths.
- The third line contains an integer max_length.
Output format:
- Output a single integer representing the length of the longest valid contiguous subarray.
Example:
Input:
5
2 1 3 4 5
8
Output:
4
(The longest sequence is [2, 1, 3, 4])
Key concepts
two_pointersarrayssubarrays
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