Taking 1 out of 3 consecutives
Submissions: 2791   Accuracy:

30.39%

  Difficulty: Medium   Marks: 4

Given an array consisting of N non-negative numbers your task is to find the minimum sum of the array such that out of 3 consecutive  elements you need to add at-least one.

Input:
First line consists of T Test cases. Each test case contains 2 lines . The first line consists of a number N specifying the number of elements in an array and the next line contains N elements.

Output:
Output in a single line minimum sum that can be obtained.

Constraints:
1<=T<=100
1<=N<=43

Example:
Input:
2
6
1 2 3 6 7 1
12
1 2 3 6 7 1 8 6 2 7 7 1
Output:
4
7

Explanation:
For First Test case moving from left to right 3+1
For second Test case moving from left to right 3+1+2+1. When 3 is added next 3 consecutive elements be 6 7 and 1 and so on.

** For More Input/Output Examples Use 'Expected Output' option **

Author: Ayush Saluja


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.