The problem is to find the count of each digit (0 to 9), which occur in integers starting from 1, upto a given integer n.
A brute force approach is to consider each and every digit in all the integers from 1 to n. This will have a complexity of O(n), which is not feasible if n is greater than 10^7.
The approach discussed here has a very less complexity than the brute approach. The complexity is O(number of digits in n)!
Read full article from CODING INTERVIEW ARCHIVES
No comments:
Post a Comment