How to calculate number of permutations of a string which may contain repeated elements?

The length of the string is <=300.
The formula to calculate this is n!/(a!*b!*c!..)
Answer should be modulo of 10^9+7.

How to code this as n is very large??

  • If you are a Java programmer, and want a quick solution, simply use BigInteger
  • If you are a Python programmer, you need not worry about the size of the number
  • If you are a C programmer, or a language that doesn’t support BigIntegers, you need to use the concept of modular arithmetic, in particular, modular division. You can read up on it here