395. Count Commas in Range II

MediumMath

You are given an integer n. Return the total number of commas used when writing all integers from [1, n] (inclusive) in standard number formatting. In standard formatting: - A comma is inserted after every three digits from the right. - Numbers with fewer than 4 digits contain no commas. Note: because n can be as large as 10^15, both n and the answer are passed and returned as strings.

Examples

Input: 1002

Output: 3

Explanation: "1,000", "1,001", and "1,002" each contain one comma → 3 total.

Constraints

  • 1 <= n <= 10^15
Loading...

Run checks all cases above. Submit evaluates all test cases.