Search⌘ K
AI Features

Solution: Third Maximum Number

Explore how to determine the third maximum distinct element in an array or return the maximum if fewer than three distinct elements exist. This lesson teaches using a min heap combined with a set to track unique numbers efficiently, optimizing for both 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 <= ...