0

Subsequnce or Subset of an array

How to find the subsequence or subset of an array that contain n elements? Can anyone explain me how to do. Preferably in C++

22nd Feb 2019, 11:53 AM
Aadhish Sriram
Aadhish Sriram - avatar
19 Answers
+ 1
Can you explain me with an example
22nd Feb 2019, 12:31 PM
Sahil Bhakat
Sahil Bhakat - avatar
+ 1
Oh let me see i will tell you in a minute
22nd Feb 2019, 12:56 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Are asking about how to get all the values from an array ??
22nd Feb 2019, 12:28 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
I'm asking about subsequence or subset of an array Sahil Bhakat
22nd Feb 2019, 12:30 PM
Aadhish Sriram
Aadhish Sriram - avatar
0
If you have an array {1, 2, 3} then subsets are {1}, {2}, {3}, {1, 2}, {2, 3}, {1, 3}, {1, 2, 3} are subsets of that array But I need subset that contain n elements. i.e If n=2 then subsets are {1, 2}, {2, 3}, {1, 3}.
22nd Feb 2019, 12:47 PM
Aadhish Sriram
Aadhish Sriram - avatar
0
There is one problem
22nd Feb 2019, 1:11 PM
Sahil Bhakat
Sahil Bhakat - avatar
22nd Feb 2019, 1:12 PM
Aadhish Sriram
Aadhish Sriram - avatar
0
If the array is {1,2,3,4} Then the subsets you need are this - {1,2},{1,3},{1,4},{2,3},{2,4},{3,4} right?
22nd Feb 2019, 1:14 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Similar to that but it's not necessarily 2 elements it may be of any number of elements less than the size of array
22nd Feb 2019, 1:15 PM
Aadhish Sriram
Aadhish Sriram - avatar
0
Yes for 2 elements is this correct ?
22nd Feb 2019, 1:17 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Yeah it's correct
22nd Feb 2019, 1:19 PM
Aadhish Sriram
Aadhish Sriram - avatar
0
Sorry i am going somewhere so you should put another question if you are in hurry or i will do it later
22nd Feb 2019, 1:28 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Keep me posted if you can
22nd Feb 2019, 1:29 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
If you can complete it, I will leave it up to you.
22nd Feb 2019, 1:30 PM
Aadhish Sriram
Aadhish Sriram - avatar
0
Ok thanks
22nd Feb 2019, 2:09 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
m=sizeof(a)/sizeof(a[0]; for(i=0;i<m-1;i++) for(j=i,c=0;j<m-1;j++) { cout<<"{"; for(k=0;k<n;k++) { if(k=0) cout<<a[i]; else cout<<","<<a[i+c]; c++; } cout<<"}, "; } cout<<"\b";
22nd Feb 2019, 5:05 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Try this and tell me if it works or not
22nd Feb 2019, 5:06 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Not working
22nd Feb 2019, 5:10 PM
Aadhish Sriram
Aadhish Sriram - avatar
0
Ok let me check
22nd Feb 2019, 5:18 PM
Sahil Bhakat
Sahil Bhakat - avatar