Dsa
Prefix Sum
Easy
Car Mileage Tracking
You are managing a fleet of cars, and you need to keep track of the mileage of each car after a series of trips. Your input will be the mileage recorded after each trip for a specific car. Create a program that computes the cumulative mileage for that car after each trip and outputs it.
Input:
- The first line contains an integer M (1 <= M <= 100), the number of trips.
- The second line contains M space-separated integers representing the mileage added after each trip.
Output:
- Print M space-separated integers where the i-th integer represents the total cumulative mileage after the i-th trip.
Example Input:
4
50 30 20 100
Example Output:
50 80 100 200
Key concepts
prefix_sumarrayscumulative_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