Dsa
Prefix Sum
Easy
Website Visits Analysis
A website owner wants to analyze the number of visits recorded over a week. Each day, visits can increase or decrease, and you need to provide the total number of visits for any two given days.
Input format:
- The first line contains an integer W (1 ≤ W ≤ 100,000), the number of days (1 week).
- The second line contains W integers, representing the visits recorded for each day.
- The third line contains two integers, dayStart and dayEnd (0 ≤ dayStart ≤ dayEnd < W), the range for querying visits.
Output format:
- Output a single integer: the total number of visits from dayStart to dayEnd (inclusive).
Example:
Input:
7
200 300 -50 100 400 200 -150
2 5
Output:
950
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