Тёмный

FACEBOOKS #1 INTERVIEW QUESTION (2022) - MINIMUM REMOVE TO MAKE VALID PARENTHESIS [PYTHON] 

Cracking FAANG
Подписаться 17 тыс.
Просмотров 4,8 тыс.
50% 1

Опубликовано:

 

16 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 13   
@YT.Nikolay
@YT.Nikolay 2 года назад
I could not solve it when I saw this problem 1st time, I am proud that today I cracked this problem before watching your video. Thanks for posting videos, your content definitely helps me to progress!
@crackfaang
@crackfaang 2 года назад
Sometimes it’s like that. I can’t tell you how many solutions I had to look at and videos to watch before things started clicking for me. I think as long as you understand how/why a solution works, there’s no problem looking at it if you are stuck. It’s just important to learn it so that when you inevitably come across another similar question, you can apply what you learned
@YT.Nikolay
@YT.Nikolay 2 года назад
@@crackfaang I watch your videos till the end because: want to be sure my solution is optimal, 2nd watched to the end counter +=1 :)
@sagarpanwar2724
@sagarpanwar2724 8 месяцев назад
Why can’t you have a stack : push when you see ‘(‘ pop when you see’)’ if there is nothing to pop then the remaining ‘)’ are to be removed. Store the indices of ‘)’ and return the string without them. Any thing wrong with this approach?
@ketulshah5462
@ketulshah5462 3 месяца назад
I have same question.
@cfbf96
@cfbf96 3 месяца назад
you can, but in the interview they often ask you to solve without a stack
@yashshukla1637
@yashshukla1637 9 дней назад
Cleaner and more intuitive approch class Solution(object): def minRemoveToMakeValid(self, s): stack = [] s = list(s) # Iterate through the string and handle parentheses for i, c in enumerate(s): if c == "(": stack.append((i, "(")) elif c == ")": if stack and stack[-1][1] == "(": stack.pop() # Valid pair else: stack.append((i, ")")) # Unmatched closing parenthesis # Update unwanted parentheses with '-1' while stack: index, _ = stack.pop() s[index] = '' # Rebuild the final valid string return "".join(s)
@rsKayiira
@rsKayiira 2 года назад
Great video, we need more of these!!
@rezaafra9785
@rezaafra9785 6 месяцев назад
Excellent Explanation
@shuier525
@shuier525 7 месяцев назад
I feel the last several lines "elif cur_char == ")" res.append(cur_char)else:res.append(cur_char)" can be simply combined to "else:res.append(cur_char)"
@TheBIKEDEALZ
@TheBIKEDEALZ 6 месяцев назад
had this question in Amazon automation position, but failed to do it - thanks for your explanation.
@charliebitme-zb3nv
@charliebitme-zb3nv 6 месяцев назад
lovely explanation
Далее
VALID PALINDROME II [PYTHON]
11:45
Просмотров 1,2 тыс.
Holding Bigger And Bigger Dogs
00:18
Просмотров 12 млн
The Midpoint Circle Algorithm Explained Step by Step
13:33
LOWEST COMMON ANCESTOR OF A BINARY TREE III [PYTHON]
16:38
Fast Inverse Square Root - A Quake III Algorithm
20:08
Naming Things in Code
7:25
Просмотров 2,1 млн
Holding Bigger And Bigger Dogs
00:18
Просмотров 12 млн