Coders Packet

Print all Subsequences of an Array Whose Sum is K using C++

By MOHAMMAD JABIR

This Project Prints all the Subsequences of the Array whose sum is K.Input will be given by User i.e.., an Array ,K & Size of Array 'N' using C++ programming language.

Given an integer array of unique elements,value K,size of array N By the User.

Have to print all the Subsequences of the array whose sum is K.

The Subsequences must not contain duplicate

Print all Subsequences of an Array Whose Sum is K using C++

Note : 

Example 1:

Input: a = [1,2,3],N=3,K=3 
Output: [[1,2],[3]]

Example 2:

Input: a= [17, 18, 6, 11, 2, 4],N=6,K=6
Output: [[2,4],[6]]

Constraints:

  • 1 <=size of array<= 10
  • all the elements in array are unique given by the User. 

Time Complexity : O(2^n) , For the Out Side Function. 

                        O(N^2), For Printing vector<vector>ans Elements in main Function.

 

 

 

Download Complete Code

Comments

No comments yet