Lexicographical Numbers - Leetcode 386 - Python

  Рет қаралды 12,771

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 41
@AdityaSingh-th7xu
@AdityaSingh-th7xu 2 ай бұрын
Great Explanation, Always crushed my doubts 😂, Keeping Neetcoding❤
@Gojo-hl7iu
@Gojo-hl7iu 2 ай бұрын
Thank you sooo much for your daily uploads
@sriramgugulothu4195
@sriramgugulothu4195 2 ай бұрын
Very clear explanation.
@phillipwils
@phillipwils 2 ай бұрын
Excellent presentation as always. Thanks for showing the recursive and iterative solutions. By the way, I was reviewing the code by hand and I noticed that every number is visited 10 times instead of once for the recursive implementation. The time complexity is still linear. The recursive solution time complexity is Time: O(10*n) => 10 * O(n) => O(n) Verify with paper and code with n = 275 def __init__(self): self.count = 0 def dfs(start): self.count += 1 ... print(self.count) # 2759) return result n=275 dfs(1) res = [1, dfs(10) res = [1,10, dfs(100) res = [1,10,100, for [0..9] dfs(100), dfs(101), ... dfs(109) dfs(1000), dfs(1010),...dfs(1090) dfs(101) res = [1,10,100,101,
@floman3158
@floman3158 2 ай бұрын
Something about recursive functions is annoying me so much that I always try to avoid those solutions.
@leeroymlg4692
@leeroymlg4692 Ай бұрын
you should learn it. some problems are overly complicated without recursion. like binary tree
@souriksharma
@souriksharma 2 ай бұрын
I tried doing it with string for simplicity but.........yeah it exceeded the time limit and when I ran in in my IDE it took wooping 32.3 sec to sort 14959 in lexicographical order.
@satyamjha68
@satyamjha68 2 ай бұрын
Solved it using Trie !
@RIPNANI
@RIPNANI 2 ай бұрын
Bro look at the follow ups
@satyamjha68
@satyamjha68 2 ай бұрын
@@RIPNANI Ya I know that ! Its just that this approach came to my mind first!
@deepakjain4481
@deepakjain4481 2 ай бұрын
@@satyamjha68 how to solve it using that
@RIPNANI
@RIPNANI 2 ай бұрын
@@satyamjha68 k
@MP-ny3ep
@MP-ny3ep 2 ай бұрын
Great explanation as always. Thank you !
@ngoquangtrung234
@ngoquangtrung234 2 ай бұрын
Great explaination.
@_sf_editz1870
@_sf_editz1870 2 ай бұрын
Just like everyday nice and smooth
@ap2s2000
@ap2s2000 2 ай бұрын
I love you neet
@VanjeAv
@VanjeAv 2 ай бұрын
Amazing thanks
@GullemClydeCyrilS
@GullemClydeCyrilS 2 ай бұрын
awesome!
@jamescraft5300
@jamescraft5300 2 ай бұрын
hello!
@maanas_sehgal
@maanas_sehgal 2 ай бұрын
Hey I need suggestions! So I am 1526 rated on Leetcode rn and I was planning to start with neetcode sheet. Should I pursue 150 or 580 first? I mean 580 has all the types of problems but will take long. 150 has important ones😅
@neks2081
@neks2081 2 ай бұрын
dont do 580, solve 150 and then do questions by topics you suck at
@maanas_sehgal
@maanas_sehgal 2 ай бұрын
@@neks2081 k
@abdalmlck4498
@abdalmlck4498 2 ай бұрын
but how SC is 1 ? you did save it in the res ?
@albin_joby
@albin_joby 2 ай бұрын
res = [] def check(num): for i in range(0,10): val = num*10+i if val
@Sarojkumar-yh9uy
@Sarojkumar-yh9uy 2 ай бұрын
res = [] def check(num): for i in range(0,10): val = num*10+i if val
@deepakjain4481
@deepakjain4481 2 ай бұрын
i tried it but i think it does not work
@tauicsicsics
@tauicsicsics 2 ай бұрын
Can you please do Basic Calculator 1 and 2? TBH all Top Leetcode 150 interview questions would be great, thanks.
@mcbotface
@mcbotface 2 ай бұрын
Why do you make easy problems complicated? lst = [i for i in range(1,n+1)] return sorted(lst, key=lambda x:str(x)) This solution had 59ms runtime and runtime was better than 96.89% solutions.
@NeetCodeIO
@NeetCodeIO 2 ай бұрын
Try to compare the time complexity of your solution with mine. Maybe you will figure it out. Maybe not.
@mcbotface
@mcbotface 2 ай бұрын
@@NeetCodeIO Yeah my solution has TC of O(NlogN) while yours has O(N)
@gmh14
@gmh14 2 ай бұрын
@@mcbotface ????? the question states TC should be O(n)
@mcbotface
@mcbotface 2 ай бұрын
@@NeetCodeIO You were right. I get "memory limit exceeded" for today's POTD using yesterday's approach return sorted([i for i in range(1,n+1)], key=lambda x:str(x))[k-1]
@mcbotface
@mcbotface 2 ай бұрын
@@gmh14 No I guess. That's why my solution was accepted. Although the TC was O(NlogN)
@100nitishyadav8
@100nitishyadav8 2 ай бұрын
why people using dfs in this, i just made a list from 1 to n the custom sorted it using comparator by converting into string is that bad solution ?
@homelander.lover9114
@homelander.lover9114 2 ай бұрын
Constraint I O(n), sorting is n logn
@33galactus
@33galactus 2 ай бұрын
@@homelander.lover9114 Exactly, your solution is simple but O(nlogn) time and O(n) space complexity make it sub-optimal.
@mohammedsuhail.s192
@mohammedsuhail.s192 2 ай бұрын
i think it was not a bad solution but the contraint should play in the problem because they want to be space complexity should be O(1) so we dont create any extra space for that it is my intuation
@sriramgugulothu4195
@sriramgugulothu4195 2 ай бұрын
There is a constraint of running algorithm in O(n). Sorting takes more than O(n).
@austinmclaughlin8407
@austinmclaughlin8407 2 ай бұрын
You're the modern day Gayle Laakmann McDowell
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 151 М.
Can You Find Hulk's True Love? Real vs Fake Girlfriend Challenge | Roblox 3D
00:24
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Microservices Gone Wrong at DoorDash
17:22
NeetCodeIO
Рет қаралды 161 М.
Snakes and Ladders - Leetcode 909 - Python
21:22
NeetCode
Рет қаралды 54 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 695 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 650 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 629 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 303 М.
Most Beautiful Item for Each Query - Leetcode 2070 - Python
17:17
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,7 МЛН
COMPUTER SCIENCE explained in 17 Minutes
16:49
Wacky Science
Рет қаралды 1,5 МЛН