Is this equivalent to generate all the combinations of order k and sort the generated strings before to print them?

Example:

string = "abcd" k = 3

k-permutations:

a,b,c a,c,b b,a,c b,c,a c,a,b c,b,a

These strings sort all the same way, i.e. "a,b,c"

So, the idea is to generate all the possible combinations (ranging K from 0 to N), remembering to sort the string right before to emit it to the console.

Thoughts?

I posted the algo to generate all the combination of string recently on this blog. Findi it and change the print line as follow:

Is this equivalent to generate all the combinations of order k and sort the generated strings before to print them?

ReplyDeleteExample:

string = "abcd"

k = 3

k-permutations:

a,b,c

a,c,b

b,a,c

b,c,a

c,a,b

c,b,a

These strings sort all the same way, i.e. "a,b,c"

So, the idea is to generate all the possible combinations (ranging K from 0 to N), remembering to sort the string right before to emit it to the console.

Thoughts?

I posted the algo to generate all the combination of string recently on this blog. Findi it and change the print line as follow:

System.out.println(sort(str));

Ciao!

anything better? this is a little hard

ReplyDelete