Given an integer N, the task is to find the smallest and largest N-digit numbers in Hexa-Decimal Number System.
Input: N = 4
Input: N = 2
Approach: The following steps can be followed to compute the required answer:
- Largest Number: To get the largest number, every digit of the number must be maximum. The maximum digit in the Hexa-Decimal number system is ‘F‘. Therefore:
1 Digit Largest Number: 'F' 2 Digit Largest Number: 'FF' 3 Digit Largest Number: 'FFF' . . . N Digit Largest Number: 'FFF....(N) times'
- Smallest Number: The smallest number in hexadecimal number is ‘0‘. The idea is that the first digit needs to be as minimum as possible other than 0 which is ‘1’ and the remaining digits needs to be 0. Therefore:
1 Digit Smallest Number: '1' 2 Digit Smallest Number: '10' 3 Digit Smallest Number: '100' . . . N Digit Smallest Number: '100....(N - 1) times'
Largest: FFFF Smallest: 1000
Time Complexity: O(N) where N is the length of the string.
Attention reader! Don't stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Smallest and Largest sum of two n-digit numbers
- Largest and Smallest N-digit Octal Numbers
- Sum and product of k smallest and k largest prime numbers in the array
- Sum and product of k smallest and k largest composite numbers in the array
- How to add two Hexadecimal numbers
- Check the divisibility of Hexadecimal numbers
- Find the count of natural Hexadecimal numbers of size N
- Smallest and Largest Palindrome with N Digits
- Largest and smallest digit of a number
- Smallest and Largest N-digit perfect squares
- Smallest and Largest N-digit perfect cubes
- Queries for the smallest and the largest prime number of given digit
- Smallest and Largest N-digit number starting and ending with N
- Split the number into N parts such that difference between the smallest and the largest part is minimum
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Largest Even and Odd N-digit numbers
- Smallest number divisible by first n numbers
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Largest Even and Odd N-digit numbers of base B
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnkitRai01