Dsa
Prefix Sum
Easy
Product Sales Growth
You are analyzing the growth of product sales over a series of months. Each month's sales figures are recorded as integers. Write a program that calculates the total sales over a specific range of months.
Input format:
- The first line contains an integer M (1 ≤ M ≤ 100,000), the number of months.
- The second line contains M integers, representing the sales figures for each month.
- The third line contains two integers, fromMonth and toMonth (0 ≤ fromMonth ≤ toMonth < M), indicating the range of months.
Output format:
- Output a single integer: the total sales from fromMonth to toMonth (inclusive).
Example:
Input:
6
150 200 50 300 100 250
1 4
Output:
950
Key concepts
prefix_sumrange_query
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