Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Find the Middle Value Among Three Distinct Numbers

Basic Acceptance 82.79% Points 10

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.

Examples
Example 1

Input: a = 3, b = 9, c = 5
Output: 5
Explanation: 5 lies between 3 and 9, making it the middle value.

Example 2

Input: a = 10, b = 2, c = 6
Output: 6
Explanation: 6 is neither the smallest value (2) nor the largest value (10).

Example 3

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.

Constraints
  • -109 = each number = 109
  • All three numbers are distinct.
Topics
Comparisons
Companies
Microsoft
Added 30 Oct 2026 82.79% acceptance
Ln 1, Col 1Sign in to save your code
3 1 2
2