Armstrong Number

A positive integer is called an Armstrong number (also known as a narcissistic number) when the sum of each of its digits raised to the power of the total…

A positive integer is called an Armstrong number (also known as a narcissistic number) when the sum of each of its digits raised to the power of the total digit count equals the number itself. For example, a 3-digit number `n` is an Armstrong number if `d1³ + d2³ + d3³ = n`, where `d1`, `d2`, `d3` are its individual digits. Given a positive integer `n`, return `true` if `n` is an Armstrong number, and `false` otherwise.

- `1 <= n <= 10^8` - The input is always a positive integer. - Single-digit numbers (1 through 9) are always Armstrong numbers because each digit raised to the power 1 equals itself.

Example 1: input n = 407; output true. 407 has 3 digits. 4³ + 0³ + 7³ = 64 + 0 + 343 = 407. The sum equals the number itself.

Example 2: input n = 219; output false. 219 has 3 digits. 2³ + 1³ + 9³ = 8 + 1 + 729 = 738, which does not equal 219.

Example 3: input n = 8208; output true. 8208 has 4 digits. 8⁴ + 2⁴ + 0⁴ + 8⁴ = 4096 + 16 + 0 + 4096 = 8208.

Category: Math. Topic: math. Difficulty: Easy. Patterns: math.