Search⌘ K
AI Features

Solution: Third Maximum Number

Discover how to identify the third distinct maximum element in an integer array by leveraging a min heap and set to track unique values. This lesson teaches you to handle duplicates, maintain the top three numbers efficiently, and return the correct result with optimal time and space complexity.

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 <= ...