0
0
DSA Javascriptprogramming~10 mins

BST Find Maximum Element 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 find the maximum value in a BST by moving right.

DSA Javascript
function findMax(root) {
  if (!root) return null;
  let current = root;
  while (current.[1] !== null) {
    current = current.right;
  }
  return current.value;
}
Drag options to blanks, or click blank then click option'
Aleft
Bchild
Cparent
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' to find the maximum.
Not checking if the root is null before starting.
2fill in blank
medium

Complete the code to return null if the BST is empty.

DSA Javascript
function findMax(root) {
  if ([1]) return null;
  let current = root;
  while (current.right !== null) {
    current = current.right;
  }
  return current.value;
}
Drag options to blanks, or click blank then click option'
A!root
Broot === undefined
Croot.value === null
Droot.left === null
Attempts:
3 left
💡 Hint
Common Mistakes
Checking root.value instead of root itself.
Using root.left to check if tree is empty.
3fill in blank
hard

Fix the error in the loop condition to correctly traverse the BST to find the maximum.

DSA Javascript
function findMax(root) {
  if (!root) return null;
  let current = root;
  while (current.[1]) {
    current = current.right;
  }
  return current.value;
}
Drag options to blanks, or click blank then click option'
Aleft
Bvalue
Cright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using current.left in the loop condition.
Checking current.value instead of current.right.
4fill in blank
hard

Fill both blanks to complete the function that finds the maximum value in a BST.

DSA Javascript
function findMax(root) {
  if ([1]) return null;
  let current = root;
  while (current.[2] !== null) {
    current = current.right;
  }
  return current.value;
}
Drag options to blanks, or click blank then click option'
A!root
Broot === null
Cleft
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' in the loop.
Checking 'root === null' instead of '!root'.
5fill in blank
hard

Fill all three blanks to complete the function that finds the maximum value in a BST safely.

DSA Javascript
function findMax([1]) {
  if ([2]) return null;
  let current = root;
  while (current.[3] !== null) {
    current = current.right;
  }
  return current.value;
}
Drag options to blanks, or click blank then click option'
Aroot
B!root
Cright
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' instead of 'root' as parameter.
Not checking if root is null or undefined.
Moving left instead of right in the loop.