Custom Sort String | 2 Approaches | Intuition | Meta | Leetcode 791

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=oGPfmp71Zm4



Duration: 28:33
3,993 views
239


iPad PDF Notes - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Leetcode-791-Custom%20Sort%20String.pdf
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 35th Video of our Playlist "Strings : Popular Interview Problems".
In this video we will try to solve a very good string problem : Custom Sort String | 2 Approaches | Intuition | Meta | Leetcode 791

Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with the hashtag #codestorywithmik & feel free to tag me.

Comparator in C++ - https://youtu.be/Eht8pA9Qz58?si=gg24rzQUoCGDoDbj

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.

Problem Name : Custom Sort String | 2 Approaches | Intuition | Meta | Leetcode 791
Company Tags : META (Facebook)
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/HashMap/Custom%20Sort%20String.cpp
Leetcode Link : https://leetcode.com/problems/custom-sort-string/


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
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


Approach Summary :
Approach-1:
This approach involves counting the frequency of each character in the given string `str` using an array `count`. Then, it iterates through the characters in the specified order and appends them to the result string according to their frequencies. Finally, it appends the remaining characters in the original order. This approach has a time complexity of O(str.length()) and a space complexity of O(26) ~ O(1), as it uses a constant-sized array to store character frequencies.

Approach-2:
This approach utilizes a comparator to sort the characters in the string `str` based on their positions in the specified order. It initializes a vector `index` to store the positions of characters in the order. The sorting is performed using the `sort` function with a lambda comparator. The time complexity is O(nlogn) due to the sorting operation, and the space complexity is O(26) ~ O(1) as the vector `index` is of constant size. This approach provides an alternative solution by directly sorting the characters based on the specified order.

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

✨ Timelines✨
00:00 - Introduction
04:18 - Approach-1
10:43 - Approach-2
22:09 - Coding it up

#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-03-18Task Scheduler | Easy Intuition | Using Heap | Leetcode 621 | codestorywithMIK
2024-03-17Minimum Deletions to Make String K-Special | 2 Simple Approaches | Leetcode 3085 | codestorywithMIK
2024-03-16Count Substrings Starting and Ending with Given Character | Leetcode 3084 | codestorywithMIK
2024-03-16Shortest Common Supersequence | 3 Approaches | DP On Strings |DP Concepts & Qns 20|codestorywithMIK
2024-03-15Contiguous Array | Using same Pattern Approach | Similar Problems | Leetcode 525
2024-03-15Trie VS Tree
2024-03-14Binary Subarrays With Sum | 2 Approaches | Detailed Explanation | Leetcode 930
2024-03-13Find the Pivot Integer | 5 Approaches | Easy Explanation | Leetcode 2485
2024-03-12Regular Expression Matching | Brute Force | Optimal | Recursion Concepts And Questions
2024-03-11Shortest Uncommon Substring in an Array | Detailed Intuition | Dry Run | Leetcode 3076 | Contest 388
2024-03-10Custom Sort String | 2 Approaches | Intuition | Meta | Leetcode 791
2024-03-10Maximum Strength of K Disjoint Subarrays | Recursion | Memoization | Leetcode 3077 | Contest 388
2024-03-09Intersection of Two Arrays | 4 Approaches | Leetcode 349
2024-03-08Minimum Common Value | 3 Approaches | Leetcode 2540
2024-03-07Count Elements With Maximum Frequency | One Pass | Two Pass | Leetcode 3005
2024-03-07Happy International Women’s Day, 2024 #womensday #codestorywithmik
2024-03-06Spend your time wisely #codestorywithMIK #motivation #hardwork
2024-03-04Minimum Length of String After Deleting Similar Ends | Simple Two Pointers | Leetcode 1750
2024-03-04Stay tuned - Life Changing Moment
2024-03-04Largest Number formed from an Array | Largest Number | Comparators Application | Leetcode 179
2024-03-02Remove Nth Node From End of List | 1 Pass | 2 Pass | Leetcode 19