Problem
Ask
Submissions

Problem: Third Maximum Number

Easy
15 min
Explore how to identify the third distinct maximum number in an integer array by applying the top k elements pattern with heaps. Learn to handle arrays with fewer than three distinct elements by returning the maximum, and implement your solution in a coding environment. This lesson solidifies problem-solving skills for coding interviews with practical examples.

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 <= nums.length <=103<= 10^3

  • 231<=-2^{31} <=nums[i]<=2311<= 2^{31}-1

Problem
Ask
Submissions

Problem: Third Maximum Number

Easy
15 min
Explore how to identify the third distinct maximum number in an integer array by applying the top k elements pattern with heaps. Learn to handle arrays with fewer than three distinct elements by returning the maximum, and implement your solution in a coding environment. This lesson solidifies problem-solving skills for coding interviews with practical examples.

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 <= nums.length <=103<= 10^3

  • 231<=-2^{31} <=nums[i]<=2311<= 2^{31}-1