Leetcode Problem 2592. Maximize Greatness of an Array

2592. Maximize Greatness of an Array

Leetcode Solutions

Two Pointers Approach

  1. Sort the array nums in ascending order.
  2. Initialize two pointers, i at 0 and j at 1.
  3. Initialize a counter cnt to 0.
  4. While j is less than the length of nums, do the following: a. If nums[j] is less than or equal to nums[i], increment j. b. If nums[j] is greater than nums[i], increment both i and j, and increment cnt.
  5. Return the counter cnt as the result.
UML Thumbnail

Sort and Heap Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...