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
|
98 Discussions
|
Please Login in order to post a comment
the part I don't like Hackerrank is that some problem is like a min math-oplymiad – in case you don't know the math concept/formula behind you cannot get the solution right even if you got the right idea/thought about how to solve.
For example, this problem comes down to count how many permutations are there for the left half of palindrome (and then times that by number of odd chars) – and the answer is the multinomial (n, k).
Anyway I got the code right, but cannot think of why it still got "time exceeded" – the multinomial calculation should be minimal, I'm not using factor(n) at atll. would appreciate if some big-shot in math can point out how to further improve
n res //= i n -= 1 return res
This is rubbish problem. In C++, we can use long double which is 128-bit on a 64-bit processor/OS. If I modulo everywhere, the result ends up smaller than expected. If I modulo only at the end, it ends up bigger than expected. And why does this test case have a smaller count?
compared to:
My answer with Typescript, Has runtime error with few very very large test 100.000+ that idk where cause 50kb limit test
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