I knew the general idea but kept second-guessing myself on the boundary conditions.
Clarify the definitions of floor and ceiling, then traverse the BST iteratively, updating candidate values based on comparisons with the target. Leverage the BST property to achieve O(h) time and O(1) space.
Pro tip: Explicitly state that floor is the greatest value ≤ target and ceiling is the smallest value ≥ target, and handle edge cases like when no floor or ceiling exists. This shows attention to detail and prevents misinterpretation.
Confirm that floor is the largest value ≤ target and ceiling is the smallest value ≥ target. Discuss what to return if no such values exist (e.g., null, -1, or a sentinel).
Decide between iterative and recursive approaches. Iterative is often preferred for O(1) space, but recursive is simpler to code.
Set floor and ceiling to null (or appropriate sentinel). Start traversal from the root.
While current node is not null: if node.val == target, set both floor and ceiling to target and break; if node.val < target, update floor to node.val and move right; if node.val > target, update ceiling to node.val and move left.
After traversal, return the floor and ceiling values. If either remains null, indicate that no such value exists.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.