Decoding '_Brilliant_' Permutations

If we take all possible Unique Permutations of the string ' BRILLIANT ' in Lexicographic order , what would be the position of the string ' ABRLLITNI ' ?


The answer is 990.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Lokesh Sharma
Dec 31, 2013

Solution with Python: import itertools

lst = list(itertools.permutations('BRILLIANT'))
lst.sort()

newLst = [lst[0], ]
for i in lst[1:]:
    if newLst[-1] != i:
        newLst.append(i)

print newLst.index(('A', 'B', 'R', 'L', 'L', 'I', 'T', 'N', 'I')) + 1

>>> 990

First consider ordering the letters of the word 'BRILLIANT'. That gives us the string 'ABIILLNRT' , which is the first possible permutation in lexicographic order.

There are 362880 actual possible permutations but not all of them are unique. Consider using 'Sets' (mathematically a set cannot contain duplicates) to store all possible permutations in lexicographic order. Obviously you 'll find that the string 'ABRLLITNI' is at position 990 !

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...