Dsa
Prefix Sum
Easy
Circular Range Audit
An array of N sensors is arranged in a circle. You are given the sensor readings in order from 0 to N-1. You must process Q queries, where each query provides a start index 'i' and an end index 'j'. You need to return the sum of readings from 'i' to 'j'. If i <= j, it is a standard range. If i > j, the range wraps around the end of the array to the beginning (i.e., i, i+1, ..., N-1, 0, 1, ..., j).
Example:
Input:
4
10 20 30 40
2
0 2
3 1
Output:
60
70
Explanation:
Query 0-2: 10+20+30=60. Query 3-1: 40 (idx 3) + 10 (idx 0) + 20 (idx 1) = 70.
Key concepts
prefix_sumcircular_array
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