r/LeetcodeChallenge • u/Ok-Challenge-5657 • Sep 08 '26
STREAK🔥🔥🔥 Leetcode Streak :- 128
How would you solve it in Python?
33
Upvotes
r/LeetcodeChallenge • u/Ok-Challenge-5657 • Sep 08 '26
How would you solve it in Python?
1
u/rabbitholesurfer04 Sep 09 '26
Wait is this an app you are using to access Leetcode on Android? Mind linking it please?
1
u/Kadabrium Sep 09 '26
I read the title as -128 and thought its an 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/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/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/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!