LeetCode 414: Third Maximum Number | DSA Series Day 21
Welcome back to Day 21 of my Data Structures and Algorithms (DSA) series! Today, we are taking on a great fundamental array problem: LeetCode 414 - Third Maximum Number. In this video, we are asked to find the third distinct maximum number in an array, and if it doesn't exist, we must return the absolute maximum. While it's easy to just sort the array or use a Hash Set, those approaches can take O(N log N) time or extra memory. I will walk you through a highly optimized O(N) time and O(1) space solution in C++ by keeping track of just our top three maximum values. We will also carefully handle tricky edge cases like integer overflow and arrays with less than three distinct elements! Code Repository & Solutions: Get the full C++ source code for this problem and all my series solutions on my GitHub: https://github.com/SaptakBhattacharyya/leetcode-soln-by-saptak.git Connect with Me: Track my progress and connect with me on LeetCode: https://leetcode.com/u/SaptakBhattacharyyaCodez/ Timestamps: 0:00 - Intro & Day 21 Welcome 0:35 - Understanding the Problem & Edge Cases (LeetCode 414) 1:50 - The Naive Sorting Approach vs. O(N) Optimization 3:15 - Tracking the Top 3 Variables Logic 4:30 - Writing the C++ Code 6:15 - Time & Space Complexity Analysis (O(N) Time, O(1) Space) 7:30 - Outro & What's Next for Day 22 Tags: #DSA #LeetCode #LeetCode414 #ThirdMaximumNumber #Arrays #Optimization #DataStructures #Algorithms #CompetitiveProgramming #CodingInterview #SoftwareEngineering #C++
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.