741. Check Armstrong Number Recursively

EasyRecursionRecursion

An Armstrong number (also called a narcissistic number) of k digits is a non-negative integer that equals the sum of its own digits each raised to the power k. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. Given an integer n, return true if it is an Armstrong number, otherwise return false. Negative numbers are NOT Armstrong numbers. Implement digit extraction and the digit-power sum recursively.

Input: A single integer n.

Output: Return a boolean: true or false (lowercase).

Examples

Example 1
Input: 153
Output: true
Explanation: 1^3 + 5^3 + 3^3 = 153.
Example 2
Input: 9474
Output: true
Explanation: 9^4 + 4^4 + 7^4 + 4^4 = 9474.
Example 3
Input: 100
Output: false
Explanation: 1^3 + 0^3 + 0^3 = 1, not 100.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →