Sum of Infinite Array Problem Statement
Given an array A
of N
integers, construct an infinite array B
by repeating A
indefinitely. Your task is to process Q
queries, each defined by two integers L
and R
. For each query, calculate the sum of elements from index L
to R
(inclusive) in the infinite array B
.
Return the sum modulo 10^9 + 7
.
Example:
Input:
A = [1, 2, 3], Queries = [(1, 3), (2, 5)]
Output:
6 9
Explanation:
For the first query, the subarray from index 1 to 3 in B
is [1, 2, 3], and the sum is 6. For the second query, the subarray from index 2 to 5 is [2, 3, 1, 2], and the sum is 9.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= A[i] <= 10^9
1 <= Q <= 10^4
1 <= L <= R <= 10^18
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
Be the first one to answer
Add answer anonymously...
Top TCS Technical Associate interview questions & answers
Popular interview questions of Technical Associate
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app