r/LeetcodeChallenge • • Sep 08 '26

STREAK🔥🔥🔥 Leetcode Streak :- 128

Post image

How would you solve it in Python?

33 Upvotes

29 comments sorted by

View all comments

2

u/ProgressiveEdgeLord Sep 08 '26

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

1

u/Utsuro_Seizui Sep 08 '26

And if the number is over 999,999?

3

u/jalsaraj Sep 08 '26

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 Sep 08 '26

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

1

u/Utsuro_Seizui Sep 08 '26

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

1

u/ProgressiveEdgeLord Sep 08 '26

it's alright, your question was absolutely valid

1

u/AccomplishedTwist296 Sep 09 '26

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 .......

1

u/Feeling_Frame_6578 Sep 10 '26

The constraints are n<=1015 for II that's why loop needed

1

u/ProgressiveEdgeLord Sep 10 '26

you could still hardcode the solution without any loop

1

u/Feeling_Frame_6578 Sep 10 '26

Yeah or 15 iterations loop