The code is running fine, but the sub sequences are not in lexicographical order .
Question https://hack.codingblocks.com/contests/c/925/73 3
Code https://ide.codingblocks.com/s/115480 1
Problem in Recursion-All Subsequences
Here you are directly printing the formed subsequences in the base case…the recursive approach will not get you the output in lexicographical order by itself…instead you can push the formed subsequence to a vector or an array in the base case… Outside the recursive function, you can make a separate function for sorting the formed susequence in the vector/array lexicographically…
Now I’m storing the subsequences in array,but when I try display the elements of array.It is only giving the last character of every subsequence.Why is it so?And how to correct it?
Code https://ide.codingblocks.com/s/115982
Check your mistake.
Also after that you need to sort the array to get lexicographical order
Now the code is running fine ,but while submitting on hacker blocks,the test case is not being passed.
Here is the code
Check your code is not properly sorting
for test case:
2
ab
acd
o/p:
a
ab
b
a
ac
acd
ad
cd
c
d
Here cd is comming before c which is wrong.
You can use the STL sort function for sorting the strings lexicographically
Now I’m using the inbuilt sort function from STL,but still the test case is not being passed.
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.