Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6381 |

@blackshadows | 6329 |

@mb1973 | 5388 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@1905439 | 553 |

@terabaap123 | 508 |

@smitadiwedi1991 | 279 |

@DevanandJayakumar | 250 |

@atishagusain | 244 |

@gupta_10 | 226 |

@nipun edara | 224 |

@shubhamkhullar7 | 224 |

@sharmachandan487 | 204 |

@balunagar | 204 |

@arshjit_singh7 | 190 |

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

...