Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the middle index of the array.
DSA Go
mid := (start + [1]) / 2
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(arr) instead of end index.
Using start twice instead of end.
✗ Incorrect
The middle index is calculated by averaging the start and end indices.
2fill in blank
mediumComplete the code to create a new tree node with the middle element.
DSA Go
node := &TreeNode{Val: [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using arr[start] or arr[end] instead of arr[mid].
Using arr[0] which is always the first element.
✗ Incorrect
The root node value is the middle element of the current array segment.
3fill in blank
hardFix the error in the recursive call to build the left subtree.
DSA Go
node.Left = sortedArrayToBST(arr, start, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid as end index includes the middle element again.
Using end includes elements after mid.
✗ Incorrect
The left subtree uses the array segment before the middle element, so end index is mid - 1.
4fill in blank
hardFill both blanks to build the right subtree correctly.
DSA Go
node.Right = sortedArrayToBST(arr, [1], [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid as start includes middle element again.
Using start or mid incorrectly as end index.
✗ Incorrect
The right subtree uses the array segment after the middle element, from mid + 1 to end.
5fill in blank
hardFill all three blanks to complete the base case and recursive call.
DSA Go
if [1] > [2] { return nil } mid := (start + end) / 2 node := &TreeNode{Val: arr[mid]} node.Left = sortedArrayToBST(arr, start, [3]) return node
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using start >= end in base case instead of >.
Using mid or mid + 1 for left subtree end index.
✗ Incorrect
The base case checks if start > end to stop recursion. The left subtree uses end index mid - 1.