Ctrl K

Sum of Digit Powers

Easy
Let number have exactly k digits. Raise every digit to the power k and add the results up. Return true if the sum equals number itself, and false otherwise.
Example 1
number=370 → True

Three digits, so the power is 3: 3³ + 7³ + 0³ = 27 + 343 + 0 = 370.

Example 2
number=25 → False

2² + 5² = 29 ≠ 25.

Example 3
number=8 → True

A one-digit number always equals itself to the first power.

Constraints
  • 1 ≤ number ≤ 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
number=370
Expected
True

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