Ctrl K

Divisible by Its Digit Sum

Easy
You are given a positive integer x. Add up its digits. If x is evenly divisible by that sum, return the sum. Otherwise return -1.
Example 1
x=27 → 9

The digits add up to 2 + 7 = 9, and 27 is divisible by 9, so the answer is 9.

Example 2
x=35 → -1

The digit sum is 8, and 35 is not divisible by 8, so the answer is -1.

Example 3
x=100 → 1
Constraints
  • 1 ≤ x ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
x=27
Expected
9

Run checks the first 3 tests in your browser. Submit checks all 56 tests on the server, hidden ones included.