Dsa
Prefix Sum
Medium
Website Visit Tracking
You are keeping track of website traffic over a month. Given a list of daily visits recorded as changes from the previous day, you need to calculate the total number of visits for a specified range of days. Assume day 1 starts with 0 visits.
Input format:
- The first line contains an integer N (1 ≤ N ≤ 30).
- The second line contains N integers representing daily visit change records.
- The third line contains two integers A and B (1 ≤ A ≤ B ≤ N).
Output format:
- An integer representing the total number of visits between day A and day B.
Example:
Input:
7
100 200 -50 300 -100 150 100
3 5
Output:
350
Key concepts
prefix_sumcumulative_statisticsrange_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