Generate Parentheses - Leetcode 22

  Рет қаралды 8,520

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 8
@VarunKumar-id6qv
@VarunKumar-id6qv 2 сағат бұрын
Dude I just got selected for NVIDIA. It just happened that i follow you and it paid off big time !!! Thankyou ❤❤❤
@ceciljoel9577
@ceciljoel9577 Сағат бұрын
What was the interview problem how would you rate it in terms of leetcode difficulty?
@VarunKumar-id6qv
@VarunKumar-id6qv Сағат бұрын
Medium problem but you have be good at explaining stuffs while coding
@ArcticFoxCodes
@ArcticFoxCodes 20 сағат бұрын
Didn't want to take the time to code, but gave it some thought. Seems like the type of problem that one could come up with a fancy binary combinatorics solution or a dynamic programming solution. But, as I said, didn't care to take the time to work it out...
@彩色糖果-i4i
@彩色糖果-i4i 20 сағат бұрын
From a Java user perspective, it looks like a list
@xingyuxiang1637
@xingyuxiang1637 Сағат бұрын
public class Solution { public List generateParenthesis(int n) { if (n left) { helper(left, right - 1, result, r +")"); } } } Greg's recursions are too advanced because you have a global variable and shared memory idea. They may be better for hard questions. This one is more like a dungeon-crawler game. You can find them on Leetcode, too.
@mohammedwissam2685
@mohammedwissam2685 14 сағат бұрын
Way easier to solve it using dp.
@xingyuxiang1637
@xingyuxiang1637 24 минут бұрын
ans = set() stack = [([], 0, 0)] # (state, left, right), where state is the list of parentheses while stack: state, left, right = stack.pop() if len(state) == 2*n and "".join(state) not in ans: ans.add("".join(state)) if left < n: state.append("(") stack.append((state.copy(), left+1, right)) state.pop() if right < left: # never add or ")" than existing "(" state.append(")") stack.append((state.copy(), left, right+1)) # state.pop() # not really needed-speeds up to omit return list(ans) This one is more like question 22 and also fits the order of drawing the tree. But still one needs to know how the stack mimics the tree. You can try a BFS algorithm or rework that as long as the right brackets are less than the left brackets, then keep branching. Of course, all these codes are on Leetcode, too. In short, recursions run backward.
Have coding interviews gotten harder?
3:51
NeetCodeIO
Рет қаралды 124 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 40 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 695 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 8 МЛН
Noob Coder vs Douche Dev
0:55
Greg Hogg
Рет қаралды 71 М.
Prefix Sum in 4 minutes | LeetCode Pattern
4:13
AlgoMasterIO
Рет қаралды 7 М.
Top 5 algorithms for interviews
0:47
Sahil & Sarra
Рет қаралды 633 М.
The IMPOSSIBLE Laptop Fan...
14:19
Dave2D
Рет қаралды 923 М.
Europe's Missing Trillions
10:01
Bloomberg Originals
Рет қаралды 587 М.
Why France’s Economy is Doing Better Than it Looks
9:26
TLDR News EU
Рет қаралды 157 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 209 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 40 МЛН