Search⌘ K
AI Features

Solution: Third Maximum Number

Explore how to determine the third distinct maximum number in an integer array using a min heap and a set to track unique values. Learn steps to handle duplicates and maintain the top three distinct elements with efficient 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 <= ...