Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find All Armstrong Numbers in a Range

Basic Acceptance 89.12% Points 10.00

You are given two integers L and R. Your task is to print all Armstrong numbers in the inclusive range [L, R] in ascending order, separated by spaces. An Armstrong number equals the sum of its digits, each raised to the power of the total number of digits.

Examples
Example 1

Input: L = 1, R = 500
Output: 1 2 3 4 5 6 7 8 9 153 370 371 407
Explanation: These are all the Armstrong numbers in the range from 1 to 500.

Example 2

Input: L = 100, R = 200
Output: 153
Explanation: The only Armstrong number in this range is 153, because 1³ + 5³ + 3³ = 153.

Example 3

Input: L = 10, R = 99
Output: (empty)
Explanation: No two-digit numbers are Armstrong numbers, so there are no numbers to print.

Constraints
  • 1 <= L <= R <= 106
Companies
Microsoft Expedia Media.net
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