Given an integer N, the task is to find the smallest and largest N-digit numbers in Octal 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 Octal number system is ‘7‘. Therefore:
1 Digit Largest Number: '7' 2 Digit Largest Number: '77' 3 Digit Largest Number: '777' . . . N Digit Largest Number: '777....(N) times'
- Smallest Number: The smallest number in Octal 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'
Below is the implementation of the above approach:
Largest: 7777 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 Octal Number System
- Largest N digit Octal number which is a Perfect square
- Count of Octal numbers upto N digits
- Check if number is palindrome or not in Octal
- Decimal to octal conversion with minimum use of arithmetic operators
- Check if Decimal representation of an Octal number is divisible by 7
- Program to Convert Octal Number to Binary Number
- Check if an Octal number is Even or Odd
- Octal equivalents of connected components in Binary valued graph
- Program to Convert Octal to Hexadecimal
- 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
- Smallest and Largest sum of two n-digit numbers
- Largest and Smallest N-digit Hexadecimal Numbers
- Smallest and Largest N-digit number starting and ending with N
- Program to find the largest and smallest ASCII valued characters in a string
- Program to find Smallest and Largest Word in a String
- Lexicographically smallest and largest substring of size k
- Split the number into N parts such that difference between the smallest and the largest part is minimum
- Smallest and Largest N-digit perfect cubes
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.