Tough LinkedIn Coding Interview Question - JavaScript

preview_player
Показать описание
Solution to a very popular coding interview question asked recently by LinkedIn - Lowest Common Ancestor of a BST.

#softwareengineering #javascript #shorts

Background Music:
Creative Commons / Attribution 4.0 International (CC BY 4.0)
Рекомендации по теме
Комментарии
Автор

Recursion is often a good approach for trees, but this problem works well with iteration, because it doesn't need to check multiple branches:

function lowestCommonAncestor(root, p, q) {
while (root) {
if (p.val < root.val && q.val < root.val)
root = root.left;
else if (p.val > root.val && q.val > root.val)
root = root.right;
else
return root;
}
}

ZantierTasa
Автор

Amazing. Keep uploading such short and to the point topics

SiddheshPardeshi-mpcr
Автор

I make 200k and never need to use this

chriskeo
Автор

Not related but does anyone know the vs code theme used in the video?

abstract_VnSn
Автор

Did stack overflow and youtube teach you to code?

vBroadcaster
Автор

this can be done more efficiently with binary lifting.
O(log n) per query.

masaftic
Автор

I thought by lowest you meant lowest val so my idea was the same but if both nodes are greater than the root you'd return the root since going right would increase the value

duarteribeiro
Автор

Dude, we arent deaf, slow the hell down and keep text off the screen

MichaelOfRohan
Автор

It'd be cool if you were to give a real world use case

hereallyfast
Автор

Why not use a while loop and iterate each row of branches? Would this be a better solution?

couldbejake
Автор

This solution makes sense to me, but it is not passing some test cases on Leetcode for some reason. Any ideas why?

dragonborn
Автор

If you continue to accept bs questions like this, this bs will never end.

sidneymonteiro
Автор

I feel like just learning and doing a bunch of discrete math problems solves most coding questions, or at least gives you vital tools. You cant avoid the math! Get off your ass and pull out that damn textbook!

Entropy
Автор

Are they hiring people with math degree or those who can just write a good readable code that works?

adeek
Автор

it will mostly never be used anywhere. So it is useless.

renisrrenis
Автор

Why not use a while loop and iterate each row of branches? Would this be a better solution?

couldbejake
visit shbcf.ru