Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Middle Value Among Three Distinct Numbers

Basic Acceptance 82.79% Points 10.00

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
  • -10? = a, b, c = 10?
  • All three numbers are distinct.
Companies
Microsoft
Topics
Comparisons
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions