How do you find the middle of three numbers efficiently?
A simple logic puzzle asking for the median of three values. It tests conditional branching and comparison logic.
Why Interviewers Ask This
This question checks basic logical reasoning and the ability to handle multiple conditions efficiently. Interviewers want to see if candidates can minimize comparisons or use sorting tricks to find the median quickly.
How to Answer This Question
Explain comparing the three numbers to determine the median. One approach is to sort them and pick the middle one. Another is to use if-else logic to find the value that is neither the max nor the min. Mention O(1) time complexity.
Key Points to Cover
- Sorting approach
- Conditional logic
- Median definition
- Minimal comparisons
Sample Answer
To find the middle of three numbers, I can simply sort them and pick the second element. Alternatively, I can use conditional logic: if a is between b and c, a is the middle. If b is between a and c, b is the middle; oth…
Common Mistakes to Avoid
- Incorrect condition ordering
- Handling equal values poorly
- Overcomplicating the logic
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.