We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Maximum Palindromes
- Discussions
Maximum Palindromes
Maximum Palindromes
Sort by
recency
|
94 Discussions
|
Please Login in order to post a comment
The trick here is to use Fermat's little teorem for computing inverse factorials and precompute binomial coeffitiens modulo 10e9 + 7, then use them for computing the multinomial coeffitients for palindromes
My solution
The only trick here is to cache the frequency map, since you are going to use it for every single test in the test-range. Do not bother caching modinverse, etc. The real cost is the string manipulation. Do something like this in your initialize function
And of course, calculate the difference in frequencies...
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star : ) )
These links are helpfull to unserstand the problem:
https://blogarithms.github.io/articles/2019-01/fermats-theorem
https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/