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
Armstrong Number Problem OverviewInput: 153Process:Digits: 1, 5, 3 (count = 3)Calculate: 1³ + 5³ + 3³= 1 + 125 + 27 = 153Output: true153 == 153 ✓ Armstrong Number!Examples:• 9: 9¹ = 9 ✓ • 153: 1³+5³+3³ = 153 ✓ • 1634: 1⁴+6⁴+3⁴+4⁴ = 1634 ✓• 123: 1³+2³+3³ = 36 ≠ 123 ✗
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
Asked in
Google 15 Amazon 12 Microsoft 8
23.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen