You are given three distinct integers. Your task is to return the middle value — the number that is neither the largest nor the smallest.
The middle value is also known as the median of the three numbers. You must determine which number lies between the other two, regardless of their input order.
Input: a = 3, b = 9, c = 5
Output: 5
Explanation: 5 lies between 3 and 9, making it the middle value.
Input: a = 10, b = 2, c = 6
Output: 6
Explanation: 6 is neither the smallest value (2) nor the largest value (10).
Input: a = 1, b = 3, c = 2
Output: 2
Explanation: 2 is the median of the three values because it lies between 1 and 3.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
3 1 2
2
5 8 2
5