Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Third Maximum Number

XPChallenge Points: 10
levelLevel: Easy

You are given an integer array nums.
Your task is to find the third distinct maximum number in the array.
If there are fewer than three distinct numbers, return the highest number instead.
In other words:
• You must consider only unique numbers (ignore duplicates).
• If the third largest unique number exists, return it.
• Otherwise, return the largest number in the array.

Example 1:

Input: nums = [10, 5, 7, 10, 2]

Output: 5

Example 2:

Input: nums = [4, 4, 4]

Output: 4

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result