Coding Interview Prep | 3 MUST KNOW Graph Problem Tips

preview_player
Показать описание
Ace your next coding interview with these 3 graph problem tips! Graph problems are an integral part of coding interviews and the examples I go through will help you solve them faster and easier!

Check out my interview prep platform for learning the patterns!

These are 3 must know graph problem tips (with examples) that are going to help you in your next coding interview. The first tip is to know what data type to use when you are writing your search algorithm. There are a couple of options including using a class, string, or an array; however, the best way is to use just an integer. We make a 2D to 1D mapping using simple conversion formulas which end up reducing the amount of code we have to write.

The second tip is relating to how we implement typical search algorithms. In order to perform a search algorithm such as a breadth-first search or depth-first search, we must explore our neighbors in every iteration. Instead of checking each neighbor one by one, we can create a 2D array containing all of the directions that we want to check, then simply loop over all of these directions and perform the checks in one place. This simplifies our code and allows to write our solution must faster.

The last tip is under the scenario that our input is restricted, we can use our input as our visited set. In normal search algorithms, we maintain a structure to keep track of places we have already been to, but this is unnecessary if our input is restricted in some way. All we need to do is change the elements to a value outside of the bounds of our restriction.
Рекомендации по теме
Комментарии
Автор

Highly Underrated Channel! Keep up the good work man!

SR-wevl
Автор

I binge-watched the graph problem collections on your channel and now understand how easy it is to solve graph problems. Thank you so much for sharing your knowledge. I wish I saw your channel earlier

nneka-mama-chari
Автор

the equality of your content are amazing and so unique !!
liked and subscribed
keep going !!

אופירמטוטי
Автор

Best explanation ever about graph basics. I didn't know the formulas described to enqueue the coordinates, but that would be handy in an interview.
Thanks for the tips here! This was the clear and straightforward explanation about graph matrices I saw until now. :)

MgThompson
Автор

That BFS explanation for adding the nearby coordinates to queue was brilliant.. Man do more quesitons like these..
🔥

manasbolt
Автор

I really understood what it means to use these tips.

Because have suffered while solving problems.

karthikreddy
Автор

LOVE the quality. As clear as always ever! Interesting content and super practical tips![heart]

juliahuanlingtong
Автор

Great tip - Convert 2-D matrix into 1-D and process the results - Wonderful

ajaib
Автор

Amazing content! Love the way you explain with pictorially !

theghostwhowalk
Автор

Michael, the best part of all of ur videos are the preciseness of the solution and the simplicity..Awesome going dude... really loved all your videos... quite a fan of urs...good going.... start some on system design side as well... u will rock there too...

rupeshmukherjee
Автор

adjacent list is also an alternative to store graph coordinate

MinhTran-jgbx
Автор

Helped! Liked! Subscribed! Did not do it because of the cat at the end of the video though :D

sanjayshekhar
Автор

2d to 1d conversion can be understood by following..
If you have int x, y less then some int n then you can increase one of them as follows
let say x = x+y*n ..
Now x/n will give you y..
And x%n will give you x

By the way big thanks Michael 👍

sandeepkumawat
Автор

I see you pulling out all the wizardry. The 2D-to-1D conversion is pretty baeh.

BeginnerMoto
Автор

Amazing bro! Keep tricks like these coming. *.*

sachinmavi
Автор

one session only on explaining big O will be great..looking forward for that

rupeshmukherjee
Автор

Converting 2d to 1d is cool, but what if the the 2d array is changed to a bigger one?

Ddos
Автор

Since the 3rd advice is inherently destructive, you can alternatively create a copy of the matrix, or even better declare a new boolean matrix where you mark every visited coordinate as you go. Having said that I wonder in which scenarios is it better to pass the matrix as an argument vs. declaring it as a global variable?

DanielVazquez
Автор

we can use separate queues for x and y coordinate.

notexlol
Автор

Are tips 1 and 2 applicable/relevant to DFS?

Kuma
welcome to shbcf.ru