Armstrong Number - Problem
Given an integer n, return true if and only if it is an Armstrong number.
The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.
Example: 153 is a 3-digit number. 1³ + 5³ + 3³ = 1 + 125 + 27 = 153, so 153 is an Armstrong number.
Input & Output
Example 1 — Classic Armstrong Number
$
Input:
n = 153
›
Output:
true
💡 Note:
153 is a 3-digit number. 1³ + 5³ + 3³ = 1 + 125 + 27 = 153, which equals the original number.
Example 2 — Single Digit
$
Input:
n = 9
›
Output:
true
💡 Note:
9 is a 1-digit number. 9¹ = 9, which equals the original number.
Example 3 — Not Armstrong
$
Input:
n = 123
›
Output:
false
💡 Note:
123 is a 3-digit number. 1³ + 2³ + 3³ = 1 + 8 + 27 = 36 ≠ 123.
Constraints
- 1 ≤ n ≤ 231 - 1
Visualization
Tap to expand
Understanding the Visualization
1
Input Number
Given integer n to check
2
Calculate Powers
Sum each digit raised to power of digit count
3
Compare
Check if sum equals original number
Key Takeaway
🎯 Key Insight: An Armstrong number equals the sum of its digits each raised to the power of the digit count
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code