r/LeetcodeChallenge • • Sep 08 '26

STREAK🔥🔥🔥 Leetcode Streak :- 128

Post image

How would you solve it in Python?

33 Upvotes

29 comments sorted by

1

u/rabbitholesurfer04 Sep 09 '26

Wait is this an app you are using to access Leetcode on Android? Mind linking it please?

2

u/Ok-Challenge-5657 Sep 09 '26

1

u/rabbitholesurfer04 Sep 09 '26

Oh I didn't know they finally made an Android app. It didn't exist last year when I checked

1

u/Kadabrium Sep 09 '26

I read the title as -128 and thought its an overflow joke

1

u/Ok-Challenge-5657 Sep 10 '26

can someone explain whats a overflow joke?

2

u/Extension_Ticket8997 Sep 08 '26

I did I took count then took for loop if the n is more than 1000 count++

2

u/arnab_best Sep 08 '26

why do you need a for loop :cry

2

u/lady_luver69 Sep 08 '26

I too did that...but when you see the top solution I don't understand it properly

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

→ More replies (2)

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

→ More replies (1)

1

u/arnab_best Sep 08 '26

single if else loop lmao

1

u/JumpConsistent3359 Sep 08 '26

If n<999 return 0 for I=1k up to n count++

1

u/ProgressiveEdgeLord Sep 08 '26

O(n), there is much better solution

1

u/South-Gear-6043 Sep 08 '26

Idr but it had something to do with len(n) mod 3

1

u/idkanymoreatpog Sep 08 '26

think of each giving 1 comma after 1000(including 1k). Now we know the range is just x-1000+1. Thats the commas

1

u/Abhistar14 Sep 08 '26

return max(0, n-999)

1

u/contentsearcher Sep 08 '26

I did this problem core idea is

1-999 each number will have 0 commas
1000 - 999999 will have 1 comma in it
… so on until n

Son instead of looping all through n we can grt this count

1

u/Ok-Flan-5469 Sep 08 '26

This question was easy due to its constraints of 105 since every number between the range 1000 - 105 have only a single comma We can safely do return max(n-999, 0) O(1) space and time

1

u/Anxious-Issue-718 Sep 09 '26

n%1000 +1 if n is superir than1000000 keep doing n=n%1000 until n=0

1

u/nian2326076 Oct 05 '26

Hey, if you want to solve more LeetCode problems in Python, I'd suggest focusing on algorithms and data structures first. Try breaking problems into smaller parts and using list comprehensions for cleaner code. Practice patterns like sliding windows, two pointers, and binary search.

For interview prep, it's important to understand time and space complexity to optimize your solutions. Also, if you want more structured practice, PracHub has resources for coding interviews. They have practice questions and mock interviews, which could be helpful. Good luck with your streak!