Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5701 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 938 |

@bt8816103042 | 739 |

@SHOAIBVIJAPURE | 428 |

@codeantik | 412 |

@SherlockHolmes3 | 407 |

@neverevergiveup | 348 |

@mahlawatep | 347 |

@shalinibhataniya1097 | 343 |

@murarry3625 | 333 |

@saiujwal13083 | 326 |

@rohitanand | 314 |

Complete Leaderboard |

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 **n **as input parameters and returns an integer denoting the minimum sum.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ N** **≤ 10^{5}

1 ≤ Arr[i]** **≤ 10^{3}

Login to report an issue on this page.

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

Yes
Pick Values

...