Dsa
Prefix Sum
Warm-up
Elevator Weight Limit
An elevator has a maximum weight capacity C. It starts with an initial weight S already inside. For N floors, you are given the net weight change (people entering minus people exiting). Determine if the elevator's weight ever exceeds its capacity C at any point. If it does, print 'OVERLOADED'; otherwise, print 'SAFE'.
Input Format:
The first line contains three integers: N (number of floors), C (capacity), and S (starting weight).
The second line contains N integers representing the net weight change at each floor.
Output Format:
The string 'OVERLOADED' or 'SAFE'.
Example:
Input:
3 1000 800
100 200 -50
Output:
OVERLOADED
(Explanation: Start: 800. Floor 1: 800+100=900. Floor 2: 900+200=1100. 1100 > 1000, so OVERLOADED.)
Key concepts
prefix_sumthreshold_check
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