Algorithms - No Repeats Please

Not asking for help coding this out, yet. I just want to know why

permAlone("aabb") should return 8.

I think of all the permutations from those letters, the only ones that don’t repeat a letter are “baba” and “abab”

The only others I can think of are

“aabb, bbaa, baab, abba”

Unless we don’t need to use all the letters? I’m not sure about that because the example they give us keeps all the letters as they’re being rearranged.

function permAlone(str) {
  return str;
}

permAlone('aab');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26

Challenge: Algorithms - No Repeats Please

Link to the challenge:

By repeat they mean ‘put the same letter twice in order’

So aabb permutations are

aabb
aabb
aabb
aabb
abab
abab
abab
abab
abba
abba
abba
abba

bbaa
bbaa
bbaa
bbaa
baab
baab
baab
baab
baba
baba
baba
baba

I believe that is 24 total. You have to treat each character as unique so even though abba is abba they are not the same because the first a is not the second one etc. then you should remove all the ones with repeated chars.
This leaves 8.

(Just imagine that each letter was not just a plain a or b but a1 and a2 and b1 and b2)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.