0
0
DSA Typescriptprogramming~10 mins

Bottom View of 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 declare a class for a binary tree node with left and right children.

DSA Typescript
class Node {
  value: number;
  left: Node | null;
  right: Node | null;
  constructor(value: number) {
    this.value = value;
    this.left = [1];
    this.right = null;
  }
}
Drag options to blanks, or click blank then click option'
Anull
Bundefined
C0
Dthis
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined instead of null.
Assigning 0 or this which are incorrect types.
2fill in blank
medium

Complete the code to add a node to the queue for level order traversal.

DSA Typescript
queue.push({ node: currentNode, hd: [1] });
Drag options to blanks, or click blank then click option'
AcurrentNode.value
BhorizontalDistance - 1
C0
DhorizontalDistance + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting 1 instead of adding for right child.
Using node value instead of distance.
3fill in blank
hard

Fix the error in the code that updates the map with the bottom view node value.

DSA Typescript
map.set(hd, [1]);
Drag options to blanks, or click blank then click option'
Ahd
Bnode.left
Cnode.value
Dqueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using node.left or hd as value instead of node.value.
Using queue which is unrelated here.
4fill in blank
hard

Fill both blanks to complete the loop that processes nodes in the queue.

DSA Typescript
while (queue.length > 0) {
  const { node, hd } = queue.[1]();
  map.set(hd, node.value);
  if (node.left) queue.push({ node: node.left, hd: hd [2] 1 });
  if (node.right) queue.push({ node: node.right, hd: hd + 1 });
}
Drag options to blanks, or click blank then click option'
Ashift
Bpop
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() which removes from end, breaking BFS order.
Adding 1 for left child hd instead of subtracting.
5fill in blank
hard

Fill all three blanks to create the bottom view array from the map.

DSA Typescript
const sortedKeys = Array.from(map.keys()).[1]((a, b) => a [2] b);
const bottomView = sortedKeys.[3](key => map.get(key));
Drag options to blanks, or click blank then click option'
Asort
B-
Cmap
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of - in sort comparator causing wrong order.
Using forEach instead of map for transformation.