Skip to content
Onsite

Super Digit

MediumP3Coding

The super digit of a number is defined recursively: if it has one digit, that digit is its super digit; otherwise it is the super digit of the sum of its digits.

You are given n as a string of digits and an integer k. Form the number p by writing n exactly k times in a row, and return the super digit of p.

For example, n = "9875" and k = 2 gives p = 98759875.

Example 1

Input
n = "9875", k = 4
Output
8
Why
p = 9875987598759875, digit sum 116, then 8.

Example 2

Input
n = "148", k = 3
Output
3
Why
p = 148148148, digit sum 30, then 3.

Example 3

Input
n = "123", k = 3
Output
9

Constraints

  • 1 <= n.length <= 100, n contains only digits and has no leading zero
  • 1 <= k <= 10^5

Hints

Run checks the 3 visible tests, Submit all 11.