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 **A** consisting of **N **__non-negative__ integers 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.

**Example 1:**

**Input:**
N = 6
A[] = {1, 2, 3, 6, 7, 1}
**Output:**
4
**Explanation:**
Moving from left to right 3+1. When 3
is added next 3 consecutive elements
be 6, 7 and 1, from which we take 1.
Which covers all subarray of lenght 3
(3+1=4).

**Example 2:**

**Input:**
2
3 2
**Output:**
0
**Explanation:**
We won't take any element as the
array length is less than 3.

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **minSum()** which takes the array **A[]** and its size **N**** **as inputs and returns the minimum sum that can be obtained.

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

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

**Constraints:**

1 ≤ N ≤ 10^{5}

1 ≤ a[i] ≤ 10^{5}

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
Taking 1 out of 3 consecutives

...