VALID WORD ABBREVIATION | LEETCODE # 408 | PYTHON TWO POINTERS SOLUTION

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

Cracking FAANG

Cracking FAANG

Күн бұрын

In this video we are solving a very popular Facebook interview question: Valid Word Abbreviation (Leetcode # 408).
Despite being marked as an Easy level question, this one is definitely more of a medium as there are quite a few edge cases to take care of and it makes this problem quite annoying to deal with. We can solve it using a pretty straightforward two pointer solution though. Stay tuned to find out how!

Пікірлер: 35
@ReleaseTheKraken25
@ReleaseTheKraken25 3 ай бұрын
Starting my meta tagged journey. I'm all in, if I get the job, I'm coming back to thank you.
@omarllama
@omarllama 2 ай бұрын
I got this today at Meta interview.
@gangliums
@gangliums Ай бұрын
@@omarllama was it during tech screen? was it accompanied with a medium?
@omarllama
@omarllama Ай бұрын
@@gangliums Yes it was screening. I got another easy problem (recursion/stack).
@diablociscogey
@diablociscogey Ай бұрын
@@omarllama i'd got the same questions for screening too. are you on discord ?
@omarllama
@omarllama Ай бұрын
@@diablociscogey I am not on Discord but I can make an account if there are interesting things there :) Since I got ghosted by the recruiter I stopped looking for interviews, going to do a Postdoc.
@OREdwardsJR
@OREdwardsJR Жыл бұрын
> IDK who graded this on leetcode but I think they're wrong.. Yes, I agree lol. Conceptually, it's easier but it's still tricky enough to be medium. Thanks for the clear explanation!
@krishanakhatri4603
@krishanakhatri4603 9 ай бұрын
Crystal Clear Explanation!! 🖤
@akshayakumar9365
@akshayakumar9365 Жыл бұрын
Thanks for the explanation!! Should we not have an extra check "if word_ptr >= len(word) return false" after the words_ptr=steps? because what if abbr had a greater step value than the whole word?
@AustinAtchley
@AustinAtchley Жыл бұрын
It's covered by the while condition
@ainsdale7752
@ainsdale7752 2 жыл бұрын
Please could you explain the code on line 13 : "steps *10" ....why 10?
@namratasukanya8424
@namratasukanya8424 2 жыл бұрын
we want to get 12 together and not just 1 and 2 separately(abbr='i12iz4n'). Like in ex- word='internationalization', abbr='i12iz4n'
@izekoreric1310
@izekoreric1310 Жыл бұрын
I know it's been a year lol! But this is for anybody in the future. Line 13 is used to get a sequence of digits from a string. the steps * 10 creates a space for the next number in the sequence and + int(abbr[abbr_ptr]) adds the next number in the squence. for example: at first steps is 0 and int(abbr[abbr_ptr]) is 1 -> 0 * 10 is 0 then + 1 = 1 (first number in the sequence) next steps is 1 and int(abbr[abbr_ptr]) is 2 -> 1 * 10 is 10 (so the zero at the end creates the space for the next number in the sequence) then + 2 = 12. I hope this helps and I have not over complicate things lol!
@huachen9747
@huachen9747 Жыл бұрын
@@izekoreric1310thank you! This helped me
@CompulsiveProgrammerLear-qm6hj
@CompulsiveProgrammerLear-qm6hj 6 ай бұрын
​@@izekoreric1310 Indeed, it's basically the same than let numStr = ''; while (abbrIndex < abbr.length && !isNaN(abbr[abbrIndex])) { numStr += abbr[abbrIndex]; abbrIndex++; } let num = parseInt(numStr); BUT, that code approach is less memory efficient than the loop and accumulation approach (num = num * 10 + parseInt(abbr[abbrIndex])
@aribasiebel
@aribasiebel 2 жыл бұрын
Subscribed after watching this soln. Great job!
@crackfaang
@crackfaang 2 жыл бұрын
Thanks! Welcome to the channel
@dystopianNinja1289
@dystopianNinja1289 Жыл бұрын
Same lol! this guy needs more exposure.
@sarayarmohammadi3376
@sarayarmohammadi3376 3 ай бұрын
Thank you
@solar679
@solar679 2 жыл бұрын
Please explain line 13
@aribasiebel
@aribasiebel 2 жыл бұрын
"123" => 123 at each iteration you need to multiply the 'sum' by 10 so you will get 0*10 + int(1) => 1*10 + int(2) => 12*10 + int(3)
@subee128
@subee128 Жыл бұрын
Thanks
@Aureole62
@Aureole62 11 ай бұрын
I think there is an error on line 9. It should be: if int(abbr[abbr_ptr]) == 0: instead of if abbr[abbr_ptr] == 0:
@Ankit-hs9nb
@Ankit-hs9nb 2 жыл бұрын
the time complexity would be O(nlogn)? can you please explain how time complexity is O(n)?
@crackfaang
@crackfaang 2 жыл бұрын
It can’t be nlogn, there’s no log n portion here. The o(n) because in the worst case the word and the abbreviation are the same word (ie no abbreviations). Here you need to check every single character one by one to determine they are the same
@Ankit-hs9nb
@Ankit-hs9nb 2 жыл бұрын
Got it! Thanks! Recently found your channel and it is very helpful!
@AmolGautam
@AmolGautam Жыл бұрын
The test cases have been changed now , so this solution no longer works. I still like the approach to the solution.
@3rd_iimpact
@3rd_iimpact Жыл бұрын
Worked for me.
@ed2023bc
@ed2023bc 7 ай бұрын
Too fast. Not everybody has solved it for 56 times and now is bored with it.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 818 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 322 М.
[SOLVED!] Valid Word Abbreviation - LeetCode 408 - Java
11:21
Scott Hacks Code
Рет қаралды 457
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 914 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 690 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 351 М.
LOWEST COMMON ANCESTOR OF A BINARY TREE III [PYTHON]
16:38
Cracking FAANG
Рет қаралды 14 М.
5 Python Libraries You Should Know in 2025!
22:30
Keith Galli
Рет қаралды 89 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН