Narcissistic Number Checker - Problem
A narcissistic number (also known as an Armstrong number) is an N-digit number that equals the sum of its digits each raised to the power of N.
For example:
153is a 3-digit narcissistic number: 1³ + 5³ + 3³ = 1 + 125 + 27 = 1539474is a 4-digit narcissistic number: 9⁴ + 4⁴ + 7⁴ + 4⁴ = 6561 + 256 + 2401 + 256 = 9474
Write a function to check if a given number is narcissistic. Additionally, find all 3-digit and 4-digit narcissistic numbers.
Input & Output
Example 1 — 3-digit narcissistic number
$
Input:
num = 153
›
Output:
true
💡 Note:
153 has 3 digits: 1³ + 5³ + 3³ = 1 + 125 + 27 = 153, which equals the original number
Example 2 — Non-narcissistic number
$
Input:
num = 123
›
Output:
false
💡 Note:
123 has 3 digits: 1³ + 2³ + 3³ = 1 + 8 + 27 = 36, which does not equal 123
Example 3 — Single digit (always narcissistic)
$
Input:
num = 5
›
Output:
true
💡 Note:
5 has 1 digit: 5¹ = 5, which equals the original number. All single digits are narcissistic.
Constraints
- 0 ≤ num ≤ 106
- Input will be a non-negative integer
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code