Комментарии:
So I should learn java rather than phyton... Right...?
ОтветитьBFS level by level requires 2 while loops.
The outer loops as long as there are nodes in the queue.
The inner while loop goes through the current level. Either keep a count at the beginning or use another queue for the current level. Or add the children nodes in another queue.
The second problem is better with BFS. BFS from each gate. The first BFS will be exhaustive for the entire map.
The subsequent BFS from other gates will stop when they can’t improve the number (with lower numbers) of the cells. Basically, we BFS from each gate until we can’t improve the cells anymore meaning there is a gate closer in those cells.
These two problems are quite straigt forward. I doubt that the Facebook interview questions are this easy.
Ответитьis this on the phone?
ОтветитьHow many leetcode problems did you solve?
Ответить调距对焦速度的关系,每放大0.001倍,距离,对焦速度加快2%以上,需要计算
Ответитьshortest distance in a matrix is always bfs :)
ОтветитьI think i would have made a Map fuction with the key as the depth and the items as the numbers. then just average each map index.
Ответитьdonw saw the end solution of 2nd problem, but its clear that you can stop dfs if you find a lower path number same as you hit a wall
ОтветитьIf you've seen the question before, just let me know and I can give you another one
"...sure ;)"
BFS is the more optimal approach, since we want the SHORTEST results
ОтветитьI think you could optimize the last problem even it uses dfs by adding a line after if... {} else if (input[row][col] == depth) { return }
or am I wrong?
the solution to the first question is wrong if there are multiple branches. on each level, he’s only doing an average of the one parent. right solution is to keep a list of list on each level. add each level, append it to the that list of list. then loop at the end to find the average. how i was able to solve it? i did a similar problem before. not a fang engineer, but ~120 leetcode questions so far. keep going guys, we all gonna get into fang!!
Ответитьthis is like watching a title fight . Pure gold. thank you.
ОтветитьUnder the impression that your solution for the first question won’t work on binary trees with more than 2 levels. You’re only checking for the both node child’s (left and right) as they were the hole level, but that ain’t true for all cases. Despite it was in this example
Ответитьtoo many ads makes super annoy!
Ответить"If youve seen the question before just le me know and I can give another one" LMAO yea OK SURE
Ответитьto work in google,amazon,facebook is hard.
ОтветитьElon Musk on leetcode
ОтветитьBro I am very passionate in coding and problem solving but I feel like I’m struck while problem solving and some questions hard to understand even ! For example : Matrix problem i didn’t even understand
ОтветитьI’m trying to understand 2nd que ! Can someone help ! Thank you !
ОтветитьThanks Sam. Any cons to using DFS for the second question? Why did you select BFS?
ОтветитьReally liked your approach in solving problems, I cleared initial round of interview with Facebook and scheduled further rounds in next week.. Can you help me with the process and next steps?
ОтветитьThe second question looks really really hard. How are you so good at translating your concepts into perfect code? Whenever you write some code you only need syntax corrections but your logic needs no correction. You write near 99% correct code in terms of logic. How can a person improve upon their ability to translate their ideas into code?
ОтветитьCheck you instagram sam, got a question for ya, thanks
Ответить