Given a number N. The task is to find the largest and the smallest digit of the number.
Input : N = 2346
Output : 6 2
6 is the largest digit and 2 is samllest
Input : N = 5
Output : 5 5
Approach: An efficient approach is to find all digits in the given number and find the largest and the smallest digit.
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.
- Smallest and Largest N-digit number starting and ending with N
- Largest number less than N with digit sum greater than the digit sum of N
- Queries for the smallest and the largest prime number of given digit
- Count of N-digit numbers having digit XOR as single digit
- Smallest and Largest N-digit perfect cubes
- Smallest and Largest N-digit perfect squares
- Smallest and Largest sum of two n-digit numbers
- Largest and Smallest N-digit Hexadecimal Numbers
- Largest and Smallest N-digit Octal Numbers
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Largest number less than N whose each digit is prime number
- Count of Numbers in Range where first digit is equal to last digit of the number
- Find the remainder when First digit of a number is divided by its Last digit
- Last digit of a number raised to last digit of N factorial
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Largest Even and Odd N-digit numbers in Octal Number System
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Check if the first and last digit of the smallest number forms a prime
- Count numbers in a range with digit sum divisible by K having first and last digit different
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.