Complete the code to find the middle index of the array segment.
int mid = (start + [1]) / 2;
The middle index is calculated by adding start and end indices and dividing by 2.
Complete the code to create a new tree node with the middle element.
TreeNode* node = (TreeNode*)malloc(sizeof(TreeNode));
node->val = [1][mid];The node value is assigned from the array element at the middle index.
Fix the error in the recursive call to build the left subtree.
node->left = sortedArrayToBST(arr, [1], mid - 1);
The left subtree uses the start index to mid - 1 segment.
Fill both blanks to build the right subtree correctly.
node->right = sortedArrayToBST(arr, [1], [2]);
The right subtree covers from mid + 1 to end indices.
Fill all three blanks to complete the base case and recursive call.
if ([1] > [2]) return NULL; int mid = (start + end) / 2; TreeNode* node = (TreeNode*)malloc(sizeof(TreeNode)); node->val = arr[mid]; node->left = sortedArrayToBST(arr, start, mid - 1); node->right = sortedArrayToBST(arr, [3], end); return node;
The base case checks if start is greater than end. The right subtree starts from mid + 1.
