Search⌘ K
AI Features

Solution: Third Maximum Number

Explore how to determine the third distinct maximum element in an integer array by using a min heap and set to manage unique values. Understand how to maintain and update a collection of the top three elements efficiently, while handling duplicates. This lesson offers a clear step-by-step approach and provides insights into time and space complexity to help you solve similar top K element problems in coding interviews.

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