Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Second Smallest of Four Numbers

Basic Acceptance 89.17% Points 10.00

You are given four integers. Your task is to determine and return the second smallest value among them.

The numbers may contain duplicates, so the second smallest value can be equal to the smallest value if the minimum occurs more than once.

Examples
Example 1

Input: a = 3, b = 9, c = 7, d = 5
Output: 5
Explanation: The smallest value is 3, and the second smallest value is 5.

Example 2

Input: a = 2, b = 2, c = 8, d = 6
Output: 2
Explanation: The smallest value 2 occurs twice, so the second smallest value is also 2.

Example 3

Input: a = 4, b = 3, c = 2, d = 1
Output: 2
Explanation: The numbers in ascending order begin with 1, 2, making 2 the second smallest value.

Constraints
  • -10? = a, b, c, d = 10?
Companies
Microsoft Apple
Topics
Sorting Algorithms 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