Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether a Number Is Armstrong

Basic Acceptance 79.84% Points 10

You are given a positive integer n. Your task is to determine whether it is an Armstrong number. A number is an Armstrong number if it equals the sum of each of its digits raised to the power of the total number of digits.

Examples
Example 1

Input: n = 153
Output: Yes
Explanation: The number 153 has three digits, and 1³ + 5³ + 3³ = 153. Therefore, it is an Armstrong number.

Example 2

Input: n = 123
Output: No
Explanation: The number 123 has three digits, but 1³ + 2³ + 3³ = 36, which is not equal to 123.

Example 3

Input: n = 9474
Output: Yes
Explanation: The number 9474 has four digits, and 9⁴ + 4⁴ + 7⁴ + 4⁴ = 9474. Therefore, it is an Armstrong number.

Constraints
  • 1 <= n <= 109
Topics
Data Structures Basics Basics
Companies
Samsung Intuit
Added 31 Oct 2026 79.84% acceptance
Ln 1, Col 1Sign in to save your code
153
Yes