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.
- Recursive Digit Sum
- Discussions
Recursive Digit Sum
Recursive Digit Sum
Sort by
recency
|
615 Discussions
|
Please Login in order to post a comment
This problem can be solved mathematically. The result is a "digital root." Before beginning the usual calculations, it's necessary to prepare for them:
If we don't need to calculate huge values like n=861568688536788, k=100000, we can use a simple calculation:
However, both options are not entirely suitable, since they do not solve the problem head-on, through a loop and recursion.
wrong tests
Can confirm - tests are wrong: one glaring example: 123 = 1+2+3 = 6. Test expects that to be 9. Hackerrank is enterprise software confirmed.
For anyone struggling with the last test case and getting overflow: you might have to use a 64-bit integer to hold the super digit value, even if you choose to return a 32-bit integer at the end:
setting the n constraint to 10^100000 is pure evil lol