Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether a Number Is Armstrong

Basic Acceptance 79.84% Points 10.00

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
Companies
Samsung Intuit
Topics
Data Structures Basics Basics
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions