Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 578 |

@praveenbgp6 | 529 |

@rdakka | 526 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

Given an array of size N, find the smallest positive integer value that cannot be represented as sum of some elements from the array.

**Example 1:**

**Input: **
N = 6
array[] = {1, 10, 3, 11, 6, 15}
**Output: **
2
**Explanation:**
2 is the smallest integer value that cannot
be represented as sum of elements from the array.

**Example 2:**

**Input: **
N = 3
array[] = {1, 1, 1}
**Output: **
4
**Explanation: **
1 is present in the array.
2 can be created by combining two 1s.
3 can be created by combining three 1s.
4 is the smallest integer value that cannot be
represented as sum of elements from the array.

**Your Task: **

You dont need to read input or print anything. Complete the function **smallestpositive() **which takes the array and N as input parameters and returns the smallest positive integer value that cannot be represented as sum of some elements from the array.

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

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

**Constraints:**

1 ≤ N ≤ 10^{6}

1 ≤ array[i] ≤ 10^{9}

Array may contain duplicates.

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
Smallest Positive Integer that can not be represented as Sum

...