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
|
92 Discussions
|
Please Login in order to post a comment
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/
Dont understand why this result is 16, not 2
Input "wldsfubcsxrryqpqyqqxrlffumtuwymbybnpemdiwyqz" 1 15 26
Take it from test case 12.
Can someone help me, describe this?
I pre-computed all FactorialsModuloM and all (FactorialsModuloM)ToPower(M_Minus_2) - for all N in [2, 100000]. Using these everywhere but: Still geting time-out for test cases 22 - 31.
One additional step that I will try is remembering the results from each query for N, K1, K2, ..., Kr - so for any other query with these same numbers we can immediately provide the remembered result.