Leetcode 818. Race Car (Python)

preview_player
Показать описание
Leetcode 818. Race Car (Python)

In this video, I solve the Leetcode Race Car problem using Breadth First search (BFS). Very popular question with Google in panel coding interviews.

You can find code on my (Ravina Gaikawad) GitHub repository. Find the link below.

If you have any algorithm problems you want me to solve please let me know in the comments below.

Ravina Gaikawad
Pseudocoder

#codinginterview #algorithm #leetcode #python #programming #faang #dsa #youtubevideo #pseudocoder #codinginterview #algorithm #leetcode #python #programming #faang #dsa #youtubevideo #pseudocoderravina #education #job #jobapplication #jobsearch #interview #algo #datastructures #dsalgo #interviewquestions #interviewpreparation #easy #easytech #software #softwareengineer #heap #pythonprogramming #tree #binarytree #dfs #bfs #depthfirstsearch #breadthfirstsearch
Рекомендации по теме
Комментарии
Автор

How can you be sure 14:15 that is not better to continue in the wrong direction let's say for one more turn?

jaimeeduardo
Автор

how we can prove that we only need to make the reverse move when we are going away from the target.
How can we prove that being greedy will lead to an optimal solution?

deveshkumar
Автор

Ravina, You don't even need visited set :) .

codedoctor
Автор

While checking for reverse direction, Why we checking position + speed, isn't enough we only check position( < or > )target . Because positin is the actual state we are exploring.

sairam
Автор

Thank you for the video. Can you make the font bigger in future videos? It was hard to read.

schan
Автор

how to print instruction that if it is R or A i have written like this but i got wrong instruction kindly help me out where i am doing wrong
if(position == target):
print(currentInst)
return (moves, currentInst)
if(position, speed) in visited:
continue
else:
visited.add((position, speed))
currentInst+="A"
queue.append((moves+1, position+speed, speed*2, currentInst))

if(position +speed >target and speed >0) or (position +speed < target and speed < 0):
if(speed >0):
speed = -1

else :
speed = 1
currentInst+="R"
queue.append((moves+1, position, speed, currentInst))

taranjeetsingh-mkzs
join shbcf.ru