Given a number N, the task is to find the largest N-digit multiple of N.
Input: N = 2
98 is the largest multiple of 2 and is of 2 digits.
Input: N = 3
999 is the largest multiple of 3 and is of 3 digits.
Approach: The idea is to make an observation.
- If we observe carefully, a series will be formed as 9, 98, 999, 9996, 99995, …
- In the above series, the N-th term can be calculated as:
- Therefore, the number N is taken as the input and the above formula is implemented.
Below is the implementation of the above approach:
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.