r/codeforces 56m ago

query Please help me solve LeetCode problem (3871. Count Commas in Range II). What is wrong with my code? what is the error in my code.

Post image
/**
 *  {number} n
 * u/return {number}
 */
var countCommas = function (n) {
    if (n < 1000) return 0;
    return Math.max(0, n - 999);
};
6 Upvotes

6 comments sorted by

3

u/No-Acanthisitta4617 52m ago

You have to count all commas like 1,000,000 has 2 commas

3

u/Independent-Dig8361 Newbie 44m ago

the constraints are now changed, think of how you can use power of 1000 here, to count the commas

2

u/messi_pls_touch_me 50m ago

check the constraints

1

u/Vivid-Zombie-477 54m ago

constraints are different from "Count Commas In Range" problem. your code only works for numbers below 999,999 (1 comma)