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:

  1. FIRST_SUM(i): Calculates the sum of the first i numbers.
  2. 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.

Be the first one to answer
Add answer anonymously...
HexaView Technologies Applications Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter