LIFE_GOES_ON's blog

By LIFE_GOES_ON, history, 4 years ago, In English

Given a string S. How many permutations of string s is lexicographically smaller than S . If S = "cda" answer will be 3 . And the strings are {"acd","adc","cad"}.

  • Vote: I like it
  • +4
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +28 Vote: I do not like it

Why shouldn't we count cad?

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

Fix the longest common prefix and the next character. The rest are free to take whatever value you want. Possibly use the permutation with repetitions formula