Prep Sheet
Prep Sheet
1. Given an array "A" of N integers, you have also defined the new array
"B" as a concatenation of array "A" for an infinite number of times. For
example, if the given array "A" is [1,2,3] then, the infinite array "B" is
[1,2,3,1,2,3,1,2,3. ... ].
Now you are given Q queries, each query consists of two integers "L"
and "R"(1 based indexing). Your task is to find the sum of the subarray
from index "L" to "R" (both inclusive) in the infinite array "B" for each
query.
Note:
The value of the sum can be very large, return the answer as
modulus 10^9+7.
Note:
Each pair should be sorted i.e the first value should be less than
or equals to the second value.
Note:
For Example:
7 7
8 3 7
For the above tree, the length of the longest path where each
node in the path has the same value is 3 and path is 7 -> 7 -> 7 -> 7.
Where 'i' and 'j' denote the indices ranging from (0, 'N').
Note:
2. All block sizes are contiguous i.e. suppose that block 'B [ i ]' ends
at a node cur, then the block 'B [ i+1 ]' starts from the node just after
the node cur.
For Example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse linked
list is 4 -> 3 -> 2 -> 1 -> NULL and the head of the reversed linked list
will be 4.
For Example:
For Example:
Note:
1. You can return the list of values in any order. For example, if a
valid triplet is {1, 2, -3), then {2, -3, 1), {-3, 2, 1} etc is also valid triplet.
Also, the ordering of dißerent triplets can be random i.e if there
are more than one valid triplets, you can return them in any order.
2. The elements in the array need not be distinct.
3. If no such triplet is present in the array, then return an empty list,
and the output printed for such a test case will be"-1".