Digital Root — Solution & Editorial
Simulate the digit-sum loop (at most a few iterations), or use the identity: the digital root of N > 0 is 1 + (N−1) mod 9.
Complexity: O(log N)
Simulate the digit-sum loop (at most a few iterations), or use the identity: the digital root of N > 0 is 1 + (N−1) mod 9.
Complexity: O(log N)