15. All Numbers with Specific Difference
โ GFG solution to All Numbers with Specific Difference: count numbers where difference between number and sum of digits meets threshold using binary search. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input: n = 13, d = 2
Output: 4
Explanation: There are 4 numbers satisfying the conditions. These are 10, 11, 12 and 13.
- 10 - (1+0) = 9 โฅ 2 โ
- 11 - (1+1) = 9 โฅ 2 โ
- 12 - (1+2) = 9 โฅ 2 โ
- 13 - (1+3) = 9 โฅ 2 โExample 2
Input: n = 14, d = 3
Output: 5
Explanation: There are 5 numbers satisfying the conditions. These are 10, 11, 12, 13 and 14.Example 3
๐ Constraints
โ
My Approach
Binary Search on Answer
๐ Time and Auxiliary Space Complexity
๐งโ๐ป Code (C++)
โ Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated