
Problem
Solution
Submissions
Print All Armstrong Numbers in a Given Range
Certification: Basic Level
Accuracy: 67.31%
Submissions: 52
Points: 10
Write a Python program that finds all Armstrong numbers in a given range.
Example 1
- Input: start = 100, end = 1000
- Output: [153, 370, 371, 407]
- Explanation:
- Step 1: For each number in the range [100, 1000], check if it's an Armstrong number.
- Step 2: For 153: 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ✓
- Step 3: For 370: 3³ + 7³ + 0³ = 27 + 343 + 0 = 370 ✓
- Step 4: For 371: 3³ + 7³ + 1³ = 27 + 343 + 1 = 371 ✓
- Step 5: For 407: 4³ + 0³ + 7³ = 64 + 0 + 343 = 407 ✓
- Step 6: No other Armstrong numbers exist in this range.
Example 2
- Input: start = 1, end = 10
- Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
- Explanation:
- Step 1: For single-digit numbers, each number is an Armstrong number.
- Step 2: For example, 9: 9¹ = 9 ✓
- Step 3: All numbers from 1 to 9 are Armstrong numbers.
Constraints
- 1 ≤ start ≤ end ≤ 10^6
- Time Complexity: O(n * log(n))
- Space Complexity: O(k) where k is the number of Armstrong numbers found
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Calculate the number of digits in each number
- Use a loop to extract each digit and compute the sum of powers