LeetCode #414: Third Maximum Number in Array

Day 19/100 – #100DaysOfCode 🚀 Solved LeetCode #414 – Third Maximum Number (Python). Today I worked on an array problem to find the third distinct maximum number in the array. If it does not exist, return the maximum number. Approach: 1) Remove duplicates by converting the array into a set. 2) Convert it back to a list. 3) Sort the list in ascending order. 4) If the length is ≥ 3, return the third maximum element. 5) Otherwise, return the maximum element. Time Complexity: O(n log n) Space Complexity: O(n) Understanding how sets help remove duplicates efficiently 💪 #LeetCode #Python #DSA #Arrays #ProblemSolving #100DaysOfCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories