You are viewing a single comment's thread. Return to all comments →
Totally agree with you. Here's what I did in Python:
def superDigit(n, k): if len(n)==1: return n return superDigit(str(sum(map(int, n))*k),1)
This does not pass all performance tests.
It does, though :)
Hey 7ovana,
I am try to do the code as below. But not pass all the test and shows that time exceed. Any idea why this approach is slower than yours, please?
def superDigit(n, k): if len(n) == 1: return n n = n * k while len(n) > 1: n = superDigit_helper(n) return n def superDigit_helper(n): return str(sum(map(int, n)))
I hate recursion, forgot return keyword return after if clause and was wondering why my code wasn't working from the last 3 hours :'(
Instead of
if len(n)==1:
; it should be
if len(n)==1 and k==1:
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Totally agree with you. Here's what I did in Python:
This does not pass all performance tests.
It does, though :)
Hey 7ovana,
I am try to do the code as below. But not pass all the test and shows that time exceed. Any idea why this approach is slower than yours, please?
I hate recursion, forgot return keyword return after if clause and was wondering why my code wasn't working from the last 3 hours :'(
Instead of
; it should be