Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Second Largest of Four Numbers

Basic Acceptance 79.82% Points 10.00

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

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

Examples
Example 1

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

Example 2

Input: a = 10, b = 10, c = 4, d = 2
Output: 10
Explanation: The largest value 10 occurs twice, so the second largest value is also 10.

Example 3

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

Constraints
  • -10? = a, b, c, d = 10?
Companies
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