Dsa
Prefix Sum
Easy
Employee Hours Calculation
A company tracks the hours worked by its employees throughout the month. Given an array of integers representing the hours worked each day, you need to respond to queries asking for the total hours worked over a given range of days.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 31) representing the number of days.
- The second line contains n space-separated integers for hours worked each day (0 ≤ hours[i] ≤ 24).
- The third line contains an integer q (1 ≤ q ≤ 10) for the number of queries.
- The following q lines contain two integers l and r (1 ≤ l ≤ n) denoting the range of days.
Output format:
- For each query, print the sum of hours worked for that range on a new line.
Example:
Input:
5
8 9 7 6 10
2
1 3
2 5
Output:
24
32
Key concepts
prefix_sumcumulative_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