Problem Link - Second Max of Three Numbers Practice Problem in 500 difficulty rating
Problem Statement:
Write a program that accepts sets of three numbers, and prints the second-maximum number among the three.
Approach:
- Since the three integers are distinct, sorting the list of three numbers and selecting the second element will directly give the second-largest number.
- Sorting three numbers has constant time complexity
O(1)
, making this approach efficient.
Complexity:
- Time Complexity: Sorting the three numbers takes constant time
O(1)
, since there are only three elements. - Space Complexity: No extra space used.