LeetCode Entry
3870. Count Commas in Range
Count commas in numbers range
3870. Count Commas in Range easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1476
Problem TLDR
Count commas in numbers range
Intuition
Brute-force is accepted, each number to string and length/3. Clever way is to spot at most one comma under 10^5 range.
Approach
- only the first 999 doesnt have it
Complexity
-
Time complexity: \(O(1)\)
-
Space complexity: \(O(1)\)
Code
fun countCommas(n: Int)=max(0,n-999)
pub fn count_commas(n: i32) -> i32 { 0.max(n-999) }
Comments