Dsa
Prefix Sum
Medium
Event Crowd Monitoring
You're managing an event that has various entry and exit points for attendees throughout the day. Given a list of events (positive for entry, negative for exit), calculate whether the crowd at any time exceeds a given capacity.
Input format:
- The first line contains an integer N (1 ≤ N ≤ 10000) the number of events.
- The second line contains N integers representing the crowd changes (positive or negative).
- The third line contains a single integer C, the maximum capacity.
Output format:
- Print 'YES' if the crowd has never exceeded capacity at any point, otherwise print 'NO'.
Example:
Input:
5
10 -5 15 -10 -5
20
Output:
YES
Key concepts
prefix_sumcumulative_sumrange_sum
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