0
0
DSA Javascriptprogramming~10 mins

Lowest Common Ancestor in Binary Tree in DSA Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the current node is null.

DSA Javascript
if (root [1] null) return null;
Drag options to blanks, or click blank then click option'
A>
B!==
C<
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' causes wrong logic.
Using '>' or '<' to compare with null is incorrect.
2fill in blank
medium

Complete the code to check if the current node matches either of the target nodes p or q.

DSA Javascript
if (root.val [1] p.val || root.val [1] q.val) return root;
Drag options to blanks, or click blank then click option'
A!==
B===
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' causes wrong logic.
Using loose equality '==' can cause bugs.
3fill in blank
hard

Fix the error in the recursive calls to search left and right subtrees.

DSA Javascript
const left = lowestCommonAncestor(root.[1], p, q);
const right = lowestCommonAncestor(root.[2], p, q);
Drag options to blanks, or click blank then click option'
Aleft
Bright
CleftChild
DrightChild
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like leftChild or rightChild.
Recursing on the same subtree twice.
4fill in blank
hard

Fill both blanks to return the correct ancestor based on left and right subtree results.

DSA Javascript
if (left [1] null && right [2] null) return root;
Drag options to blanks, or click blank then click option'
A!==
B===
C&&
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using '===' instead of '!==' causes wrong condition.
Using logical OR '||' instead of AND '&&' changes logic.
5fill in blank
hard

Fill the blanks to return the non-null subtree result or null.

DSA Javascript
return left [1] right ? left [2] right : null;
Drag options to blanks, or click blank then click option'
A!==
B||
C&&
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' instead of '||' changes the logic.
Using '===' instead of '!==' causes wrong checks.