Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5578 |

@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 | 714 |

@Manikanta punnam | 587 |

@sriramgoparaju99 | 532 |

@praveenbgp6 | 525 |

@yashkaril4 | 517 |

@prankursharma31 | 489 |

@rdakka | 467 |

@sonamnigam1999 | 441 |

@sonamkumari63928 | 427 |

@purohitmn02 | 427 |

@shubhamstudent5 | 419 |

Complete Leaderboard |

Given an array of non-negative integers, and a value *sum*, determine if there is a subset of the given set with sum equal to given *sum*.

**Example 1:**

Input: N = 6 arr[] = {3, 34, 4, 12, 5, 2} sum = 9Output:1Explanation: Here there exists a subset with sum = 9, 4+3+2 = 9.

**Example 2:**

Input: N = 6 arr[] = {3, 34, 4, 12, 5, 2} sum = 30Output:0Explanation: There is no subset with sum 30.

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **isSubsetSum()** which takes the array arr[], its size N** **and an integer **sum **as input parameters and returns boolean value true if there exists a subset with given sum and false otherwise.

The driver code itself prints 1, if returned value is true and prints 0 if returned value is false.

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

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

**Constraints:**

1 <= N <= 100

1<= arr[i] <= 100

1<= sum <= 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
Subset Sum Problem

...