class Solution {
public long countCommas(long n) {
long result = 0;
long threshold = 1000L; // 4-digit numbers → 1 comma
while (threshold <= n) {
result += (n - threshold + 1);
threshold *= 1000L; // next comma level
}
return result;
}
}
TIME COMPLEXITY
SPACE COMPLEXITY