JavaEasyNumbers10 min
Check for an Armstrong number
Print true if n equals the sum of its digits each raised to the number of digits. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe algorithm selection, invariants, and boundary handling.
Input
One integer n.
Output
Print true if n equals the sum of its digits each raised to the number of digits.
Constraints
0 <= n <= 2147483647.
Example
Input
153
Output
true
Example 2 input
2147483647
Output
false
This example exercises a further boundary or ordering case.
Public test cases (2)
Input
153
Expected output
true
Input
123
Expected output
false
Hints (2)
- Identify the state needed to avoid recomputing work for each element.
- Count the digits and use integer multiplication for each digit power.
Target complexity: time O(d^2) · space O(1)
