Skip to content
← Back to the archive

19 August 2026

Digit Root Steps

Medium Numbers

Keep summing digits until only one is left, and count the rounds.

Given a positive integer n, repeatedly replace it with the sum of its digits until it has only one digit. Return how many rounds of summing that took. Return 0 if n already has one digit.

Constraints

  • 1 <= n <= 10**12

Function signature

def digit_root_steps(n):

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.