Relative Sort Array | Sort an array according to the other | Hashing | Leetcode DSA series | Hindi

  Рет қаралды 18,985

Hello World

Hello World

3 жыл бұрын

This is the video under the series of DATA STRUCTURE & ALGORITHM in a HASHING Playlist. We are going to solve the problem "Relative Sort Array" from Leetcode which is solved by using a vector, map in c++.
Join My Telegram channel for more Updates: telegram.me/helloworldbyprince
Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.
Sort the elements of arr1 such that the relative ordering of items in arr1 is the same as in arr2. Elements that don't appear in arr2 should be placed at the end of arr1 in ascending order.
Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]
Output:
[2,2,2,1,4,3,3,9,6,7,19]
We also Provide courses on Competitive Programming and Data structure and Algorithms. Please see our Full Playlist on our Channel.
----------------------------------------------------------------------------------------
Relative Sort Array: leetcode.com/problems/relativ...
Sort an array according to the other: practice.geeksforgeeks.org/pr...
Home Work ( Custom Sort String ): leetcode.com/problems/custom-...
code in This Video: github.com/Prince-1501/Hello_...
Pdf in this video: github.com/Prince-1501/Hello_...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
Telegram► telegram.me/helloworldbyprince
----------------------------------------------------------------------------------------
►Our Playlists on:-
►Competitive Programming: • How to start Competiti...
►C++ Full Course : • L-01 || Introduction a...
►Algorithms: • L-01 || Prefix Sum Arr...
►Data Structure: • Data Structures with C...
------------------------------------------------------------------------
🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
✨ Tags ✨
how to solve 1122. Relative Sort Array
Sort an array according to the other
How to solve 791. Custom Sort String
question asked in Google
how to crack Goldman Sachs online test
how to crack Google Interview
off-campus placement
how to learn to code for beginners
Practice Hashing data structure
hashing in data structure
Best Telegram channel for Off-campus Placement drive
hashing in a data structure in Hindi
unordered_map
#hashing #geeksforgeeks #programming

Пікірлер: 107
@deveshudhlani8295
@deveshudhlani8295 2 жыл бұрын
Literally you're doing the great work! And all those who are here and reading my comment, this series of hasing is going to help a lot in placements!! ✌🏻✌🏻
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks Devesh for your love and support
@user-ev5tm2sx6n
@user-ev5tm2sx6n 27 күн бұрын
By seeing the question I thought mujhse nhi hoga lekin phir aapne bola ki try kro to thodi sharm aa gyi and I triied aur ho gya. Thanks bro
@mdumarhabib5341
@mdumarhabib5341 21 күн бұрын
Thank you Prince Bhaijaan
@remedyiq8034
@remedyiq8034 2 жыл бұрын
BHUT MAST PADHTEY HO .... MERE KO HASHING MEI BHUT CONFIDENCE AH GYA HA. Following the golden rule of this channel ..phele khudse!!!.
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks a lot buddy 😀😊😊😊
@salmaniproductions1104
@salmaniproductions1104 Жыл бұрын
Solved by own. Thank you so much bhaiyya.
@pritishpattnaik4674
@pritishpattnaik4674 2 жыл бұрын
I tried on my own and reached almost 90% problem , but was not able to push the remaining elements of array 1 to ans vector in ascending order , great video Prince bhai
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Well done
@codecodecode1752
@codecodecode1752 6 ай бұрын
same problem
@Shubham-zu1zh
@Shubham-zu1zh Жыл бұрын
biklul esa hi kiya tha , thanks for your efforts,HW done
@eshaanmandal5150
@eshaanmandal5150 2 жыл бұрын
Custom Sorting Question was done easily after I understood this question!! Thanks for the video man !!
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Glad it helped!
@anonymous090
@anonymous090 2 жыл бұрын
I have done this before watching the video and submitted it with 0 ms. All thanks to you bhaiya💕
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Great 👍
@ayushikotiyal8466
@ayushikotiyal8466 2 жыл бұрын
i have a doubt . in a map all elements stored are in ascending order then in first loop we will get 1 first hence in output overall arr 2 elements will also be in ascending order since its a map. so how is ans correct?
@naman120
@naman120 2 жыл бұрын
class Solution { public: string customSortString(string order, string s) { unordered_map A; string s1; for(int i = 0 ; i< s.size();i++) { A[s[i]]++; } for(int i = 0 ; i< order.size();i++) { if(A.find(order[i])!=A.end()) { for(int j = 0 ; j< A[order[i]];j++) { s1=s1+order[i] ; } A.erase(order[i]); } } for(auto x : A) { for(int i = 0 ; i
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Amazing Garima
@vasujhawar.6987
@vasujhawar.6987 Жыл бұрын
whyyyyyyy.........tell us inplace or better approach. We need to change the vector arr1 itself, not use extra vector. Why take extra space................
@arbazkhan5884
@arbazkhan5884 Жыл бұрын
leetcode problem 791 is done and thanks for u encourage to first slove problem itself and then watch ur video and i'm not have that habits but now yes
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
keep learning like this and pls keep sharing
@masumali8356
@masumali8356 Жыл бұрын
you are the best.......masum.
@user-tt4pr4xh2o
@user-tt4pr4xh2o 13 күн бұрын
bhaiya what is the best way to solve dsa problems ... easy then meduim and then hard or mix ?
@akmarkan2490
@akmarkan2490 Ай бұрын
Thanks a lot
@avibirla9863
@avibirla9863 2 жыл бұрын
Bhaiya bohot achha video tha ye ....maza aa gaya ..Ly ♥️
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks a ton
@binodkepapa4746
@binodkepapa4746 3 жыл бұрын
Bro doing great job 🙏🙏
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Thanks a lot binod
@udaytewary3809
@udaytewary3809 Жыл бұрын
Homework question solve ho gya bhaiya
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
nice work uday
@user-ll5qj9tj5c
@user-ll5qj9tj5c Ай бұрын
sir constraints dekhiye ..isko hm counting sort se bhi kar skte hai
@Alokkumar-xu8sf
@Alokkumar-xu8sf 3 жыл бұрын
maza aa gaya bhaiya
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Thanks brother 😀😀
@rupal6181
@rupal6181 2 жыл бұрын
Sir , I have done your homework . Thank You
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Great
@ankur4140
@ankur4140 2 жыл бұрын
Hello bhaiya , i first found the size of the array and then applied the loop int arr1_size, arr2_size; arr1_size = sizeof(arr1)/sizeof(arr1[0]); arr2_size = sizeof(arr2)/sizeof(arr2[0]); for(int i =0;i
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
amazing code bro good work
@cr7johnChan
@cr7johnChan 2 жыл бұрын
Tried it myself,as soon as it clicked ,I was over the moon.
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Wohoo 😄😄
@abhaygupta4242
@abhaygupta4242 2 жыл бұрын
Bhaiya your lecture is very very good...
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Thanks bhai
@pritamsarkar3371
@pritamsarkar3371 3 жыл бұрын
great bro
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Thanks buddy ❤️
@pritishpattnaik4674
@pritishpattnaik4674 2 жыл бұрын
My approach vector relativeSortArray(vector& arr1, vector& arr2) { map mp; int n = arr1.size(); int m = arr2.size(); vector ans; for (int i=0 ; isecond; while (v != 0){ ans.push_back(x); v--; } } return ans; }
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
You are going great
@pritishpattnaik4674
@pritishpattnaik4674 2 жыл бұрын
@@HelloWorldbyprince thank you bhai
@Kumarb694
@Kumarb694 Жыл бұрын
thank you bhai
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
welcome brother
@surjeetsingh433
@surjeetsingh433 2 жыл бұрын
Yarr isme aapne jo second example liya h usme aur question me contradiction lag raha h kyoki question ne bola h ki arr2 ke sare elements arr1 me honge.
@amanahmed6057
@amanahmed6057 2 жыл бұрын
4:33 YE BADI ACHI BAAT KAHI AAPNE (Paresh raaval)
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks ☺️☺️ Kabhi kabhi kuch jyada hi dialogue de dete hai
@samiulislamdurjoy
@samiulislamdurjoy 2 жыл бұрын
5:02
@beinghappy9223
@beinghappy9223 2 жыл бұрын
vector relativeSortArray(vector& arr1, vector& arr2) { sort(arr1.begin(),arr1.end()); mapumap; for(int i=0;i
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Amazing buddy ❤️
@luckilygamer5462
@luckilygamer5462 2 жыл бұрын
code is not working in GFG because of sorting
@luckilygamer5462
@luckilygamer5462 2 жыл бұрын
*******************GFG Code*************************** vector sortA1ByA2(vector A1, int N, vector A2, int M) {unordered_mapumap; vectorans; for(int i=0;i
@rode_atharva
@rode_atharva Ай бұрын
class Solution { public: vector relativeSortArray(vector& arr1, vector& arr2) { map mp; vector ans; vectortemp; int m = arr1.size(); int n = arr2.size(); for(int i=0; i first); } } } return ans; } };
@PROTECHRAHUL
@PROTECHRAHUL 2 жыл бұрын
Bhaiya mujhe khud se question samj nii aata h but KZbin oe question samjne k baad me khud se jyadatar questions solve kar leta hu toh koi problem toh nhi h na
@ogbuddha7835
@ogbuddha7835 2 жыл бұрын
Placement m v yahi kroge kya
@oqant0424
@oqant0424 Жыл бұрын
15/18 done (11.12.22)
@abhijitroy1958
@abhijitroy1958 2 жыл бұрын
//logic pehele hi a gaya tha but map looping ke indentation me thora problem a raha tha , but apne itne bar bola ki khud se try karo khud se solve karo , khud se dhoka matt karo, to mai ne bhi than liya ab to khud se hi karna hai and boom , first pass me ho gaya .sukriya dat neke liye class Solution { public: vector relativeSortArray(vector& arr1, vector& arr2) { mapmpp; for(auto it:arr1){ mpp[it]++; } vectorv; for(int i=0;i
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Love ❤️ the attitude bro
@SubhamKumar-9009
@SubhamKumar-9009 3 жыл бұрын
awesome
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
keep sharing these channel
@wealthzeus
@wealthzeus Жыл бұрын
I solved it using unordered map
@evelynsummer4020
@evelynsummer4020 Жыл бұрын
Can you make video in english please really appreciate it
@remedyiq8034
@remedyiq8034 2 жыл бұрын
LEET CODE SOLUTION FOR 100 % fast result vector temp; map hash; for(int i=0;i
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Amazing 🤩🤩
@MuhammadHaddi-bs5nh
@MuhammadHaddi-bs5nh 11 ай бұрын
I done it
@HelloWorldbyprince
@HelloWorldbyprince 11 ай бұрын
nice
@MuhammadHaddi-bs5nh
@MuhammadHaddi-bs5nh 11 ай бұрын
done all
@HelloWorldbyprince
@HelloWorldbyprince 11 ай бұрын
nice Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@rajchinagundi7498
@rajchinagundi7498 Жыл бұрын
class Solution { public: vector relativeSortArray(vector& arr1, vector& arr2) { vector ans; vector temp; unordered_map mp; for(int i=0;i
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Amazing code bro
@mdumarhabib5341
@mdumarhabib5341 21 күн бұрын
Python solution(1122. Relative Sort Array) from collections import defaultdict d = defaultdict(int) for i in arr1: d[i] += 1 ans = [] for i in arr2: if i in d: ans.extend( [i] * d[i] ) del d[i] for k,v in sorted(d.items()): ans.extend( [k] * v ) return ans
@surgeonofdeath8199
@surgeonofdeath8199 2 жыл бұрын
HOMEWORK: it was literally the same question LOL class Solution { public: string customSortString(string order, string s) { string ans; //step 1 map mpp; for(auto it: s) mpp[it]++; //step 2 for(int i=0;i0){ ans.push_back(order[i]); count--;} } mpp.erase(order[i]); } //step 3 for(auto it: mpp){ int count=it.second; while(count>0){ ans.push_back(it.first); count--;} } return ans; } };
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
yhi to kah rahe the sab same hota hai basic samjhne ke baad Please, if possible then share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@eshaanmandal5150
@eshaanmandal5150 2 жыл бұрын
In Java use the TreeMap class and implement SortedMap interface class Solution{ public static int[] sortA1ByA2(int A1[], int N, int A2[], int M) { SortedMap map = new TreeMap(); for(int i : A1){ map.put(i,map.getOrDefault(i,0)+1); } int index = 0; //start from the first index for(int j : A2){ if(map.containsKey(j)){ int count = map.get(j); while(count-- > 0){ A1[index++] = j; } map.remove(j); } } for(int j:map.keySet()){ int count = (Integer)map.get(j); while(count-- > 0){ A1[index++] = j; } } return A1; } }
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
amazing bro
@masumali8356
@masumali8356 Жыл бұрын
class Solution { public: string customSortString(string order, string s) { unordered_mapmp; string ans; for(auto i:s) { mp[i]++; } for(auto i:order) { if(mp.find(i)!=mp.end()) { auto x=mp.find(i); int count=x->second; char found=x->first; while(count>0) { ans=ans+found; count--; } mp.erase(i); } } for(auto i:mp) { int count=i.second; char found=i.first; while(count>0) { ans=ans+found; count--; } } return ans; } };
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
good job
@sambhavsharma2780
@sambhavsharma2780 2 жыл бұрын
Home Work Solution :- class Solution { public: string customSortString(string order, string s) { // map the s string // traverse order string if order char is present in map then push into ans // now traverse s and push remain char into ans map mp; string ans = ""; for(int i=0; i
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
good work bro keep it up
@Atpugtihsrah
@Atpugtihsrah 3 жыл бұрын
Thanks for creating the video. Easy to understand Solution: --------------------------------------------- class Solution { public: vector relativeSortArray(vector& arr1, vector& arr2) { map map; vector res; // Get the frequency of each letter of arr1 in a map for(auto a: arr1) map[a]++; // For all the elements in arr2, get the actual freq // and add it in the result, remove them from the map for(auto a: arr2){ for(int i=0; i
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
keep learning and please share my channel
@anonymous090
@anonymous090 2 жыл бұрын
Enjoy the journey, while chasing the destination??
@Sonukumar-um3cs
@Sonukumar-um3cs 3 жыл бұрын
Tree ke sawal kb krwaoge aap??
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Ab Playlist start ho gyi hai
@algoman6589
@algoman6589 Жыл бұрын
TC: O(N) SC: O(1)(constant) public static int[] sortA1ByA2(int A1[], int N, int A2[], int M) { int []freq=new int[1000001]; for(int i: A1){ freq[i]++; } int ans[]=new int[N]; int k=0; for(int i: A2){ while(freq[i]-->0){ ans[k++]=i; } } for(int i=1;i0){ ans[k++]=i; } } return ans; }
@oqant0424
@oqant0424 Жыл бұрын
HOMEWORK QUESTION DONE class Solution { public: string customSortString(string order, string s) { mapmp; string ans=""; //traverse in s for(auto x:s){ mp[x]++; } //traverse in order for(auto y:order){ if(mp.find(y)!=mp.end()){ auto it=mp.find(y); int freq=it->second; char ele=it->first; string curr(freq,ele); ans.insert(ans.end(),curr.begin(),curr.end()); mp.erase(y); } } //traverse in mp for rest elements; for(auto it:mp){ int freq=it.second; char ele=it.first; string curr(freq,ele); ans.insert(ans.end(),curr.begin(),curr.end()); } return ans; } };
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Waoo good work
@VaibhavSutar-xm3cn
@VaibhavSutar-xm3cn 4 сағат бұрын
class Solution { //Function to sort an array according to the other array. sortA1ByA2(A1, N, A2, M){ // code here let map = new Map() for(let i=0;i 1){ A1= A1.filter(item=>item !=x) res.push(x,x) } } return [...res,...A1.sort((a,b)=>a-b)] } } solved by my own ab me sukun se ye tutorial dekh sakta hu😅😅
@surgeonofdeath8199
@surgeonofdeath8199 2 жыл бұрын
Bina dekhe code likh diya vmro..... class Solution { public: vector relativeSortArray(vector& arr1, vector& arr2) { map mpp; for(auto i:arr1) mpp[i]++; vector ans; for(int i=0;i0){ ans.push_back(arr2[i]); count--;} mpp.erase(arr2[i]); } for(auto it:mpp){ int count=it.second; while(count>0){ ans.push_back(it.first); count--;} } return ans; } };
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
waooo yaar Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@srijanshahi8587
@srijanshahi8587 Жыл бұрын
home work prob done sir
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Good 👍
@sarthakjoshi21
@sarthakjoshi21 Жыл бұрын
bro pls explain in simple manner many time in this vedio u try to explain what we are doing in this line and then u forget to explain that line and u jump to next line for explaining
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
Which point you didn’t get ?
@vinayvastrakar2788
@vinayvastrakar2788 Жыл бұрын
banda tabadtod hay
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
thanks Vinay keep learning and keep sharing my channel with your friends and in colleges
@sambhavsharma2780
@sambhavsharma2780 2 жыл бұрын
Relative Sort Array:- class Solution { public: vector relativeSortArray(vector& arr1, vector& arr2) { map mp; vector ans; // map arr1 array with their count value for(int i=0; isecond; while(value>0){ ans.push_back(key); value--; } } return ans; } };
@tilakrajchoubey5534
@tilakrajchoubey5534 2 жыл бұрын
Koi bta skta hai kya ki java me kaise hoga?
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Kaash Mai bataa paata Yaar iska solution Java me mil Jayega please ek baar Google kar lijiye aap
@tilakrajchoubey5534
@tilakrajchoubey5534 2 жыл бұрын
@Anand Pandey Thankyou
Beautiful gymnastics 😍☺️
00:15
Lexa_Merin
Рет қаралды 14 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 39 МЛН
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 6 МЛН
DARKER SIDE of SOFTWARE ENGINEERING !!
12:09
Striver
Рет қаралды 132 М.
Relative Sort Array - Leetcode 1122 - Python
7:32
NeetCodeIO
Рет қаралды 9 М.
Beautiful gymnastics 😍☺️
00:15
Lexa_Merin
Рет қаралды 14 МЛН