Question bank › Prefix Sum
Dsa Prefix Sum Easy

Parking Fee Calculation

A parking lot charges based on the number of hours a vehicle is parked. Given an array of integers where each element represents the number of hours parked by different vehicles, calculate the total fees collected for specified ranges of vehicles. Assume each hour costs a fixed amount (e.g., $5). Input format: - The first line contains an integer n (1 ≤ n ≤ 1000) - the number of vehicles. - The second line contains n space-separated integers representing hours parked (0 ≤ hours[i] ≤ 24). - The third line contains an integer q (1 ≤ q ≤ 10) - the number of queries. - The following q lines contain two integers l and r (1 ≤ l ≤ n) representing the range of vehicles. Output format: - For each query, print the total parking fees for that range on a new line. Example: Input: 5 2 3 5 1 4 2 1 3 2 5 Output: 40 40

Key concepts

prefix_sumcumulative_sumaggregation

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.