Leaderboard
Showing:
Pick Values
Easy Accuracy: 40.86% Submissions: 142 Points: 2

Given an array arr[] of N positive integers. Select values from the array such that their sum is minimum. You must pick at least 1 value from each group of 4 consecutive elements. 


Example 1:

Input:
N = 5
Arr[] = {1, 2, 3, 1, 2}
Output: 1
Explanation: There are 2 groups of 4
in the given array. The 1st group is
[1 2 3 1] and 2nd is [2 3 1 2].
Selecting the 4th element in the 
array will give the least sum as 
it belongs to both groups.



Example 2:

Input:
N = 6
Arr[] = {8, 6, 9, 10, 6, 7}
Output: 9
Explanation: There are 3 groups of 4
consecutive elements. 9 at index 2 
is the smallest element that is 
present in all 3 groups. 


Your Task:
You don't need to read input or print anything. Your task is to complete the function pickValues() which takes the array of integers arr[] and its size as input parameters and returns an integer denoting the minimum sum.



Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)



Constraints:
1 ≤ N ≤ 105
1 ≤ Arr[i] ≤ 103

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Pick Values

Output Window