Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the middle index of the array segment.
DSA Java
int mid = start + (end [1] start) / 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' causes incorrect mid calculation.
Using '*' or '/' in place of '-' leads to wrong index.
✗ Incorrect
We subtract start from end to get the length of the segment, then divide by 2 to find the middle offset.
2fill in blank
mediumComplete the code to create a new TreeNode with the middle element.
DSA Java
TreeNode node = new TreeNode(nums[1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses () instead of square brackets [] for array access.
Using curly braces or angle brackets which are invalid here.
✗ Incorrect
Array elements are accessed with square brackets [].
3fill in blank
hardFix the error in the recursive call to build the left subtree.
DSA Java
node.left = sortedArrayToBST(nums, start, [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using mid + 1 causes overlap with right subtree.
Using end or start incorrectly changes the segment.
✗ Incorrect
The left subtree uses the segment before mid, so end index is mid - 1.
4fill in blank
hardFill both blanks to complete the recursive call for the right subtree.
DSA Java
node.right = sortedArrayToBST(nums, [1], [2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using start or mid - 1 as start index for right subtree.
Using mid + 1 as end index instead of start.
✗ Incorrect
The right subtree uses the segment from mid + 1 to end.
5fill in blank
hardFill all three blanks to complete the base case and recursive structure.
DSA Java
if (start [1] end) return null; int mid = start + (end - start) / 2; TreeNode node = new TreeNode(nums[2]); node.left = sortedArrayToBST(nums, start, mid [3] 1);
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in base case.
Using parentheses instead of square brackets for array access.
Using '+' instead of '-' for left subtree end index.
✗ Incorrect
Base case returns null if start > end. Access mid element with [mid]. Left subtree ends at mid - 1.
