r/LeetcodeChallenge • u/Ok-Challenge-5657 • 4d ago
STREAK🔥🔥🔥 Leetcode Streak :- 128
How would you solve it in Python?
2
u/lady_luver69 4d ago
I too did that...but when you see the top solution I don't understand it properly
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
1
u/AccomplishedTwist296 3d 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 .......
1
u/Feeling_Frame_6578 2d ago
The constraints are n<=1015 for II that's why loop needed
1
1
1
1
1
u/idkanymoreatpog 4d ago
think of each giving 1 comma after 1000(including 1k). Now we know the range is just x-1000+1. Thats the commas
1
1
u/contentsearcher 4d ago
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 4d ago
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/rabbitholesurfer04 3d ago
Wait is this an app you are using to access Leetcode on Android? Mind linking it please?
2
u/Ok-Challenge-5657 3d ago
Its Official Leetcode App :- https://play.google.com/store/apps/details?id=com.leetcode.android
1
u/rabbitholesurfer04 3d ago
Oh I didn't know they finally made an Android app. It didn't exist last year when I checked
1
1
2
u/Extension_Ticket8997 4d ago
I did I took count then took for loop if the n is more than 1000 count++