Check if the number is armstrong

Beginner Problems Basic Maths Easy
  • Fun Fact: While the Armstrong number itself might not have a direct application in software development, the underlying logic of dealing with integer manipulation, loops, and conditionals can be found in various aspects of coding like data validation, checksum algorithms or hash functions
  • Algorithms to identify Armstrong numbers act as brain teasers to improve logical thinking and problem-solving skills which are essential in breaking down complex software development tasks
  • For instance, the concept can be used in encryption algorithms to add an extra layer of security

You are given an integer n. You need to check whether it is an armstrong number or not. Return true if it is an armstrong number, otherwise return false.


An armstrong number is a number which is equal to the sum of the digits of the number, raised to the power of the number of digits.

Examples:

Input: n = 153

Output: true

Explanation: Number of digits : 3.

1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 1 + 125 + 27 = 153.

Therefore, it is an Armstrong number.

Input: n = 12

Output: false

Explanation: Number of digits : 2.

1 ^ 2 + 2 ^ 2 = 1 + 4 = 5.

Therefore, it is not an Armstrong number.

Input: n = 370

Constraints

  • 0 <= n <= 5000

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree