
Asked in TCS
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.

Calculate the sum of elements in a subarray of an infinite array constructed from a given array.
Construct the infinite array by repeating the given array indefinitely
For each query, calculate the sum ...read more
Interview Questions Asked to Technical Associate at Other Companies
Top Skill-Based Questions for TCS Technical Associate


Reviews
Interviews
Salaries
Users

