Minimum Special Sum Problem
You are given an array ARR
of length N
. There are two operations defined for each index i
in the array:
- FIRST_SUM(i): Calculates the sum of the first
i
numbers. - LAST_SUM(i): Calculates the sum of the last
N-i+1
numbers.
The SPECIAL_SUM(i) is defined as the sum of FIRST_SUM(i)
and LAST_SUM(i)
.
Your task is to determine the minimum SPECIAL_SUM for 0 ≤ i ≤ N - 1
.
Input:
The first line of input contains an integer T
denoting the number of test cases.
The first line of each test case contains a single integer N
, where N
is the number of elements in the array.
The second line of each test case contains N
space-separated integers, denoting the array elements.
Output:
For each test case, return the minimum SPECIAL_SUM for i
in the range [0, N-1]
.
The output for each test case will be printed on a separate line.
Example:
Input:
T = 1
N = 4
ARR = [1, 2, 3, 4]
Output:
5
Constraints:
1 ≤ T ≤ 5
1 ≤ N ≤ 5 * 103
-5 * 102 ≤ ARR[i] < 5 * 102
Time limit: 1 sec
Note:
You don't need to print anything. You just need to implement the given function.
AnswerBot
2d
Find the minimum special sum for each index in an array by calculating the sum of first and last elements.
Iterate through the array and calculate the special sum for each index using the given operati...read more
Help your peers!
Add answer anonymously...
Top HexaView Technologies Applications Engineer interview questions & answers
Popular interview questions of Applications Engineer
>
HexaView Technologies Applications Engineer Interview Questions
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