I'm a non CS student with a degree in mechanical engineering. I'm trying to make a career shift towards tech and your videos are helping me so much in helping me to learn DS and algo and keeping up with daily leetcode practice in preparation for when I'm ready to start interviewing
I failed a very similar question in an OA and failed it a few days ago. I had an intuition that "a player's move can unlock a move by another player" because of other game theory leetcode questions I have done in the past. I think the word optimally has scarred me into overthinking this type of problem. After understanding the problem in the OA after, I did this daily very quickly. I quote a comment in the discussions: "It's actually very simple, if you think about this fact: "There is no move a player can make that will unlock a move by another player". Because unlocking a move by another player would mean for example removing a B in between two As which is impossible. Therefore the number of moves of each player is determined by the initial number of moves they can make." This comment is the key take away from this question IMO. Thanks for the daily.
no, i think it was captial one. i still cant forgive myself for letting such an easy problem go. this pattern will never fool me again tho.@@picnicbros
another simplification : omit the second if conditional. just put else (really sorry for that lmao). These type of thinking based problems are my favourite. Not much code to write. As long as I can think properly. Needless to say, I suck at them.
Hi neetcode thanks for sharing such beautiful lessons. Need some help. Can you please let me know what code execution engine/framework you used for neetcode site to build the code editor. Thanks again.
Sir, can i use this code? is it is correct? i used stack method that was thought by u in previous video class Solution: def winnerOfGame(self, colors: str) -> bool: stack=[] d={'A':0,'B':0} for i in range(len(colors)): while len(stack)>=2 and stack[-1]==colors[i] and stack[-2]==colors[i]: d[colors[i]]+=1 stack.pop() else: stack.append(colors[i]) return d['A']>d['B'] Thank u...
My dumbass thought that this was similar to the stone-game II that we had solved a while back in Problem of the Day and was doing some MinMax optimization
Man, I need to do more of these, and get better at seeing the pattern, once you spell it out, it's so simple lol
I'm a non CS student with a degree in mechanical engineering. I'm trying to make a career shift towards tech and your videos are helping me so much in helping me to learn DS and algo and keeping up with daily leetcode practice in preparation for when I'm ready to start interviewing
Good luck with your preparation! You will achieve whatever you are aiming for.
Hey man I am also studying ME and doing the same thing like you here! The tutorial is really helpful. Cheer up !
I failed a very similar question in an OA and failed it a few days ago. I had an intuition that "a player's move can unlock a move by another player" because of other game theory leetcode questions I have done in the past. I think the word optimally has scarred me into overthinking this type of problem. After understanding the problem in the OA after, I did this daily very quickly.
I quote a comment in the discussions: "It's actually very simple, if you think about this fact: "There is no move a player can make that will unlock a move by another player". Because unlocking a move by another player would mean for example removing a B in between two As which is impossible. Therefore the number of moves of each player is determined by the initial number of moves they can make."
This comment is the key take away from this question IMO. Thanks for the daily.
JPMorgan?
no, i think it was captial one. i still cant forgive myself for letting such an easy problem go. this pattern will never fool me again tho.@@picnicbros
This is what I thought at first too. Thanks for the explanation , it cleared things out!
Glad to know that you are back at making Leetcode solution videos
Great explanation as always. Love the optimization in the end!
Thank you for your beautiful solution Neetcode. I did overthink this problem.
Thanks! Your channel is such a blessing.
leetcode be like:
first submission: 10000000ms
second submission: 10ms
Yes this makes complete sense 😂😂
Do More Hard Problems, like hard mediums and Hards
Also Maybe even Consider Vids About the Contests Problems.
another simplification : omit the second if conditional. just put else (really sorry for that lmao). These type of thinking based problems are my favourite. Not much code to write. As long as I can think properly. Needless to say, I suck at them.
Hi neetcode thanks for sharing such beautiful lessons. Need some help. Can you please let me know what code execution engine/framework you used for neetcode site to build the code editor. Thanks again.
Sir, can i use this code? is it is correct? i used stack method that was thought by u in previous video
class Solution:
def winnerOfGame(self, colors: str) -> bool:
stack=[]
d={'A':0,'B':0}
for i in range(len(colors)):
while len(stack)>=2 and stack[-1]==colors[i] and stack[-2]==colors[i]:
d[colors[i]]+=1
stack.pop()
else:
stack.append(colors[i])
return d['A']>d['B']
Thank u...
u the best
My dumbass thought that this was similar to the stone-game II that we had solved a while back in Problem of the Day and was doing some MinMax optimization
I solved using second approach but sliding window looks better
Awesome
Leetcode simulating redlining algorithms now 💀
I got mine down to 62 ms, and beat 100% python users
class Solution:
def winnerOfGame(self, colors: str) -> bool:
count = [colors.count('A'), colors.count('B')]
players = [0, 0]
for i in range(len(colors)-2):
if (colors[i] == colors[i+1] == colors[i+2]):
players[colors[i] == 'B'] += 1
if abs(count[colors[i] == 'B'] - count[colors[i] != 'B']) > 270: # players[1]
sliding window
why the hell your narration sounds like a horror story