Introduction
Programmers ususally go to an interview and the company asks to write the code of some program to check your logic and coding abilities.
You can write the code in any language like C, C++, Java, C# and so on. There is no required language and technology because the company wants to check your ability to think, your skills to write the code.
Some companies only want the algorithm to check your skills.
One of the programs in those common programs is the following.
Question
You are given an array of integers. Write a function to find a list of sub-sets within the given array sum of whose elements are equal to the given integer "requiredSum". If more than one such sub-set exists then find all of them.
For Example
Input array = [ 1, 2, 3, 4, 5, 6, 7]
requiredSum= 12
output = [ 3, 4, 5]
Input array = [ 6, 2, 3, 10, 5, 9, 12]
requiredSum= 21
output = [ 6, 2, 3, 10] and [ 9, 12]
Function Prototype
- void FindRequiredSumSubArray(int[ ] array, int requiredSum)
Create a new console application named "ConsoleApplication1".

Where you will get the page that will look like:

Now I will provide the procedure for creating the code.




MH RostamiPosted Sep 6, 2020, 9:50 AM
This solution only works with certain sets. For instance if we have {1, 2, 8} and look for a subset with the sum of 9 this algorithm has no output
Anantha NarayananPosted Mar 11, 2019, 11:42 AM
Hi..are we considering all the possible sub set here..in first example [5,7] also a subset which is equal to required sum 12
Dana MuisePosted Apr 15, 2017, 8:00 PM
This only works with consecutive sets?
Dhaval JaviyaPosted Sep 9, 2015, 2:43 AM
is it work with large value like 730,728 not like 1,2,3
Rahul Kumar SaxenaPosted Mar 29, 2015, 1:04 PM
Good work
Gowtham RajamanickamPosted Mar 28, 2015, 12:26 PM
great one..