Compute permutations with repeated letters | Optiver Interview Question