AlgoInsight

DSA problem

Armstrong Number

EasyMathPattern: MathbeginnerFree

Given an integer N, decide whether it is an Armstrong (narcissistic) number: a number equal to the sum of each of its digits raised to the power of the digit count. For example, 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.

First count the number of digits d. Then extract each digit, raise it to the power d, and accumulate the total. If the total equals the original number, it is an Armstrong number.

Known examples include every single-digit number, plus 153, 370, 371, 407, 1634, 8208, and 9474. The problem reinforces digit-by-digit processing and highlights properties that depend on a number's representation, not just its value.

Examples

Example 1
Input: N = 153
Output: true
Explanation: 153 has 3 digits and 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153, so it is an Armstrong number.
Example 2
Input: N = 123
Output: false
Explanation: 1^3 + 2^3 + 3^3 = 1 + 8 + 27 = 36, which is not 123.

Constraints

3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.

math

Browse all DSA problems