Search⌘ K
AI Features

Solution: Third Maximum Number

Understand how to implement a solution that determines the third distinct maximum number in an integer array by using a min heap and set to track unique values. Explore the step-by-step approach to handle duplicates and maintain the top three maximum elements efficiently.

Statement

Given an integer array nums, determine and return the third distinct maximum element in the array. If the array contains fewer than three distinct elements, return the maximum element instead.

Constraints:

  • 1<=1 <= ...