Given a string:
String words = \"Mary had a little lamb\";
how to obtain a combination of sentence fragments while the order of occurrence of w
Think about it this way:
Mary <1> had <2> a <3> little <4> lamb
Each of these
s can be either true or false. If it is true, then you cut the sentence in that location.
So, if you have n+1 words, your problem gets reduced to going through binary representation of numbers with n bit, that is from 0 to 2^n-1
Examples:
0110 -> {'Mary had', 'a', 'little lamb'}
1111 -> {'Mary', 'had', 'a', 'little', 'lamb'}
0001 -> {'Mary had a little', 'lamb'}
1011 -> {'Mary', 'had a', 'little', 'lamb'}