0
0
DSA Typescriptprogramming~10 mins

Lowest Common Ancestor in Binary Tree in DSA Typescript - 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 Typescript
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 != instead of ===
Using assignment operator = instead of comparison
Checking for undefined instead of null
2fill in blank
medium

Complete the code to check if the current node is either p or q.

DSA Typescript
if (root [1] p || root [1] q) 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 ===
Using > or < which are not suitable for equality checks
3fill in blank
hard

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

DSA Typescript
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
Swapping left and right
4fill in blank
hard

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

DSA Typescript
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 !==
Using logical OR instead of AND
5fill in blank
hard

Fill the blank to return the non-null subtree or null if both are null.

DSA Typescript
return left [1] right;
Drag options to blanks, or click blank then click option'
A&&
B===
C!==
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using && which requires both to be true
Using equality operators which are not suitable here