Digital Root Calculator

Easy
math digits simulation
Problem Description

Given a positive integer, find its digital root. The digital root is obtained by repeatedly summing all digits until a single digit is reached.

Input Format
A single positive integer n (1 ≤ n ≤ 10^9)
Output Format
A single digit representing the digital root
Constraints
1 ≤ n ≤ 10^9
Sample Input/Output
Input:
9875
Output:
2
Explanation

9875 → 9+8+7+5 = 29 → 2+9 = 11 → 1+1 = 2

Solution Hints
  • Read carefully: Understand input/output format and constraints
  • Start simple: Think of brute force solution first, then optimize
  • Edge cases: Consider empty inputs, single elements, max constraints
  • Data structures: Choose arrays, hash maps, sets based on problem needs
  • Time complexity: Ensure your solution fits within time limits
  • Test examples: Verify logic with provided sample inputs
100
Points
2000ms
Time Limit
256MB
Memory Limit
Code Editor
Register to Submit
Register to Access Code Editor

Create a free account to solve coding problems and track your progress.

Register Now
Feedback