Subset sum equal to target sum and print in ascending order

whats the mistake in my code… ??

i genereated all subsets and sum of that subset equal t…i printed it ?

hello @hg11110000

image

u missed this case.

u r only sorting ur output.
but in question they have asked to print all rows in lexicographical order (ie first print row starting with least number , then rows starting with next smallest so on).

check output of this example for clarity->
image
.

@aman212yadav
but then also it is only printing 1 2 5 two times…rest not showing only ???

@hg11110000
image

here it should be <

@aman212yadav

then also showing wrong o/p :frowning:

@aman212yadav

but j is the index not the length so it should be till <= only

since on j’th idx also element is present

@hg11110000
check now->

j is the index of unfilled place. that means u have filled only upto j-1 .

yeah okay
@aman212yadav

and for lexico what can i do ??

put all ur vectors(convert ur output array in vector) in set(set becuase by default it will arrange in lex order also it will keep only unique entries) and then print the set

@aman212yadav

one test case failing ??

sort ur input array as well

@aman212yadav
okay answer came but why to sort input array

we already did sort out each vector before inserting in a multiset

@hg11110000

check ur code output for this case->
15
57 79 16 3 83 70 78 14 5 8 36 51 47 93 72
86

image

this is invalid output . u have included 5 twice

correct output ->
3 5 8 70
3 5 78
3 36 47
3 83
5 8 16 57
5 14 16 51
8 78
14 72
16 70

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.