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.
Usually that means your algorithm is flawed.
When you get timeouts, it means you have to optimize speed.
When you get out-of-memories, it measn you have to optimize for space.
Hint! Spoiler!
In this case, realize that the sum of digits of "big number of digits here" + ... + "big number of digits here" with the above concatenation/replication N times, and getting the sum of the huge, gigantic number, is equal to the sum of the digits "big number of digits here" times N.
i.e. with n=12345 and k=5:
# "12345" replicated 5 times = "1234512345123451234512345", if you get one of the test cases with a string 1,000 characters long, replicated 10,000 times, you end up with a number of 100,000 digits. Non-sense.sumOfDigits("1234512345123451234512345")=75# is exactly the same as 5*sumOfDigits("12345")=155*15=75# From here on, all digit-sums are quick and ease
Super Digit
You are viewing a single comment's thread. Return to all comments →
Memory Errors? Timeouts?
Usually that means your algorithm is flawed. When you get timeouts, it means you have to optimize speed. When you get out-of-memories, it measn you have to optimize for space.
Hint! Spoiler!
In this case, realize that the sum of digits of
"big number of digits here" + ... + "big number of digits here"
with the above concatenation/replicationN
times, and getting thesum
of the huge, gigantic number, is equal to the sum of the digits"big number of digits here"
timesN
.i.e. with
n=12345
andk=5
:SOLUTION (SPOILER) IN HASKELL
Full solution here (FULL SPOILER): Rhaseven7h's Gists
Hope this helps some one.