Least Number of Unique Integers after K Removals | 3 Approaches | Greedy | Leetcode 1481

Subscribers:
94,700
Published on ● Video Link: https://www.youtube.com/watch?v=O5v9Tqv2ZDA



Duration: 43:42
2,660 views
0


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 27th Video of our Playlist "Greedy : Popular Interview Problems".
We will try to understand the thought process behind solving such Qns.

Problem Name : Least Number of Unique Integers after K Removals | Leetcode 1481
Company Tags : Amazon
My solutions on Github : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Greedy/Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals.cpp
Leetcode Link : https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/


Approach Summary :
Approach-1 (Using Map and Sorting): This approach uses an unordered_map to count the frequency of each element in the input array. Then, it creates a vector of frequencies, sorts it, and iterates through the sorted frequencies while decrementing the removal count. The process continues until the removal count becomes non-positive, and the remaining unique elements are returned.

Approach-2 (Using min-heap): Similar to Approach-1, this approach uses an unordered_map to count element frequencies. However, instead of sorting, it utilizes a min-heap (priority_queue) to keep track of frequencies. It iteratively pops the smallest frequencies from the heap and updates the removal count until it becomes non-positive, then returns the size of the heap.

Approach-3 (Using Counting Sort): This approach counts the frequency of each element and uses counting sort to create an array (freqCount) representing the count of elements with a specific frequency. It then iterates through the frequencies, calculating the number of unique elements to remove based on the removal count (k). The process continues until the removal count is exhausted, and the remaining unique elements are returned. The counting sort results in a linear time complexity.

My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction
0:18 - Problem Explanation
5:52 - Approach-1 Intuition
9:10 - Time and Space Complexity of Approach-1
9:58 - Important Note
12:51 - Coding Approach-1
14:50 - Approach-2 Explanation
16:39 - Time and Space Complexity of Approach-2
17:52 - Coding Approach-2
19:41 - Approach-3 Detailed Explanation
39:45 - Coding Approach-3

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear




Other Videos By codestorywithMIK


2024-02-24Find All People With Secret | 4 Approaches | Google | Leetcode 2092
2024-02-23Thank you and Love You All ❤️🙏
2024-02-23N-Queens | 2 Approaches | Super Detailed | Magic Of Recursion | Recursion Concepts And Questions
2024-02-21Bitwise AND of Numbers Range | 2 Approaches | Dry Run | Leetcode 201
2024-02-19Missing Number | Multiple Approaches | Leetcode 268
2024-02-19Flattening a Linked List | Magic Of Recursion | Recursion Concepts And Questions | Video 13
2024-02-18Power of Two | Multiple Approaches | Leetcode 231
2024-02-18Meeting Rooms III | Detailed Intuition | Brute Force | Optimal | Leetcode 2402
2024-02-16Furthest Building You Can Reach | What is Lazy Greedy | Recursion | Memoization | Leetcode 1642
2024-02-16Flatten BST to sorted list | Magic Of Recursion | Recursion Concepts And Questions | Video 12
2024-02-16Least Number of Unique Integers after K Removals | 3 Approaches | Greedy | Leetcode 1481
2024-02-15Rat in a Maze Problem | Simple Story To Code | Recursion Concepts And Questions | Video 11
2024-02-14Find Polygon With the Largest Perimeter | Thought Process | Greedy | Leetcode 2971
2024-02-14Subsets | Simple Story To Code | Leetcode 78 | Recursion Concepts And Questions | Video 10
2024-02-13Rearrange Array Elements by Sign | 2 Approaches | Why Order Preserve | Leetcode 2149
2024-02-13Quick Sort | Simple Story | Story To Code | Recursion Concepts And Questions | Video 9
2024-02-12Find First Palindromic String in the Array | Multiple Ways | Leetcode 2108
2024-02-11Cherry Pickup II | 3 Approaches | Super Detailed | Leetcode 1463
2024-02-10Tumlog saath ho. Bas kaafi hai ❤️ 18K family #codestorywithmik
2024-02-09Palindromic Substrings | Blueprint | Palindrome Problems | 4 Approaches | Leetcode 647
2024-02-08Largest Divisible Subset | LIS Variant | DP Concepts & Qns-18 | Leetcode-368