Day-23
🚀 Today's Problem was all about finding the number of digit '1' in a range.
I solved trailing zeroes by counting factors. Similarly, here I count how many times '1' appears between 1 and n using digit-place analysis. 🧠
Approach: 💡
🔢 Break n into parts:
Higher digits: Left of the current digit.
Current digit: The one you're counting.
Lower digits: Right of the current digit.
Counting logic:
If the current digit is 0, count based on higher digits.
If the current digit is 1, count higher + lower + 1.
If the current digit > 1, count all possible combinations.
🌀 Iterate through place values (ones, tens, hundreds).
Complexity:
⏱ Time: O(log n)
🧮 Space: O(1)
Quantitative Behavioral Designer
3moTomas, always with great ideas to improve Public Health! Cheers