Back to Browse

Minimum Increment to Make Array Unique | Sorting | Counting Sort | Leetcode 945 | codestorywithMIK

7.4K views
Jun 14, 2024
29:00

Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 34th Video of our Playlist "Greedy Technique : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a good practice greedy sorting Problem : Minimum Increment to Make Array Unique | Sorting | Counting Sort | Leetcode 945 | codestorywithMIK We will specifically see why a normal Greedy approach will fail and why we go with the Backtracking Approach for this problem. I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY. We will do live coding after explanation and see if we are able to pass all the test cases. Also, please note that my Github solution link below contains both C++ as well as JAVA code. Problem Name : Minimum Increment to Make Array Unique | Sorting | Counting Sort | Leetcode 945 | codestorywithMIK Company Tags : will soon update My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Minimum%20Increment%20to%20Make%20Array%20Unique.cpp Leetcode Link : https://leetcode.com/problems/minimum-increment-to-make-array-unique My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo Instagram : https://www.instagram.com/codestorywithmik/ Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/ Twitter : https://twitter.com/CSwithMIK Subscribe to my channel : https://www.youtube.com/@codestorywithMIK ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗ ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣ ╠╗║╚╝║║╠╗║╚╣║║║║║═╣ ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝ Summary : Approach 1: Using Sorting Time Complexity: O(nlogn) Space Complexity: O(1) Steps: Sort the array nums. Initialize a variable moves to keep track of the number of increments. Iterate through the sorted array starting from the second element. For each element, if it is not greater than the previous element, increment it to make it unique and update moves with the number of increments made. Return the total number of moves. Pros: Simple and easy to understand. Efficient for small to moderately sized arrays. Cons: Requires sorting the array, which may not be optimal for very large arrays. Approach 2: Using Counting Sort Time Complexity: O(n+maxVal) Space Complexity: O(n+maxVal) Steps: Find the maximum value in the array to determine the size of the counting array. Initialize a counting array count of size n+maxVal. Populate the count array with the occurrences of each value in nums. Iterate through the count array to ensure all values are unique: If the count of any value is more than 1, move the excess to the next value and update moves accordingly. Return the total number of moves. ✨ Timelines✨ 00:00 - Introduction #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 #newyear2024

Download

1 formats

Video Formats

360pmp430.2 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Minimum Increment to Make Array Unique | Sorting | Counting Sort | Leetcode 945 | codestorywithMIK | NatokHD