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.
(looks like no test cases start with n == 1 and k > 1)
'''
public static int superDigit(string n, int k)
{
if (n.Length == 1) return Convert.ToInt32(n);
var sum = 0L;
n.ToList().ForEach(c => sum += Convert.ToInt64(Char.GetNumericValue(c)));
if (k > 1) sum += sum * (k - 1);
return superDigit(Convert.ToString(sum), 1);
}
}
'''
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
C# Solution
(looks like no test cases start with n == 1 and k > 1)
''' public static int superDigit(string n, int k) { if (n.Length == 1) return Convert.ToInt32(n);
} '''