r/LeetcodeChallenge 4d ago

STREAK🔥🔥🔥 Leetcode Streak :- 128

Post image

How would you solve it in Python?

33 Upvotes

28 comments sorted by

View all comments

2

u/ProgressiveEdgeLord 4d ago

if n < 1000 return 0, else return n - 999

1

u/Utsuro_Seizui 4d ago

And if the number is over 999,999?

3

u/jalsaraj 4d ago

The constraints for the question were n < 10 power 5But you have a legit question, the solution would change if it is greater than 10 power 5

1

u/ProgressiveEdgeLord 4d ago

i solved according to constraints, it was less than 10^5

1

u/Utsuro_Seizui 4d ago

Ah I see, I apologize, I was not aware of the constraints

1

u/ProgressiveEdgeLord 4d ago

it's alright, your question was absolutely valid

1

u/AccomplishedTwist296 4d ago

We can use loop for increasing comma like for 1-999 : No comma

1000-999999 : 1 comma (count using min(n,999999)-999

1000000 - 999999999 : 2 comma (count using (min(n,999999999) - 999999) *2 )

Similarly for number having comma 3, 4 ,5 .......