Тёмный

Lecture 76: Heaps in C++ || Interview Questions || Part - 2 

CodeHelp - by Babbar
Подписаться 567 тыс.
Просмотров 116 тыс.
50% 1

In this Video, we are going to solve a lot of Problems based on Binary Heaps.
There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “
Visit Crio: www.crio.do/redeem/781e2f5/
Discord Server Link: / discord
Course Flow: whimsical.com/dsa-4-placement...
Notes Link: drive.google.com/drive/folder...
Slides Link: drive.google.com/file/d/1E9IV...
Code Links: github.com/loveBabbar/CodeHel...
Questions Links:
- Kth Largest Sum Subarray: www.codingninjas.com/codestud...
- Merge K sorted Arrays:www.codingninjas.com/codestud...
- Merge K sorted Linked List: www.codingninjas.com/codestud...
Do provide you feedback in the comments, we are going to make it best collectively.
Connect with me here:
Instagram: / lovebabbar1
Twitter: / lovebabbar3
Telegram Group Link: Love Babbar CODE HELP
telegram.me/lovebabbercodehelp
My Editor: rishu.rsing...
Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.
Timestamps:
00:00 - Question 1
02:50 - Promotion
03:40 - Approach #1
09:55 - Approach #2
12:05 - Code
15:40 - Question 2
17:00 - Approach #1
19:50 - Approach #2
22:50 - Code
33:35 - Question 3
35:10 - Approach #1
37:49 - Approach #2
41:30 - Code
#DSABusted #LoveBabbar

Опубликовано:

 

4 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 214   
@harsh4638
@harsh4638 2 года назад
Ek or puree youtube ka sabse best lecture
@vishalmangla1832
@vishalmangla1832 2 года назад
if today i get the job its because love bhaiya .you are such an amazing mentor i have ever seen.
@praveensorat6193
@praveensorat6193 Год назад
TC of first q is O(N^2 log(k)), N^2 since two loops and log k to heapify it.
@ayushsinha5512
@ayushsinha5512 6 месяцев назад
k will be very small
@neerajgarg9096
@neerajgarg9096 2 года назад
*In 1st question* T.C will decrease O(N^2Log(k))
@alexrcrew1975
@alexrcrew1975 2 года назад
it will increase if k is greater than 10 it will increase the time
@adityaawasthi7694
@adityaawasthi7694 2 года назад
@@alexrcrew1975 pls explain
@Shivam-kz2dg
@Shivam-kz2dg Год назад
@@alexrcrew1975 why 10 why not 2 ? Log we take here has base val 2
@priyanshkumar_iitd
@priyanshkumar_iitd 4 месяца назад
Yes T.C. of heap solution is O(n^2 . log(k))
@challengeAceiver
@challengeAceiver Год назад
Overdose hogaya bhaiya😂😂. Lekin usi baat ke to package hai. Btw jordar content bhaiya, jitni tareef karu utni kamm hai
@parthsharma5966
@parthsharma5966 2 года назад
consistency dono ka high hai bhaiya.... thanks
@vaibhavagarwal5367
@vaibhavagarwal5367 2 года назад
Thanks for this helpful lecture i am salute you for your consistency and i also try my best to be consistent
@aakashbhargavaa
@aakashbhargavaa 2 года назад
your content is really very awesome helping a lot of students. Thank you for this course. thanks a lot
@RaghavSharma-ln1qj
@RaghavSharma-ln1qj 5 месяцев назад
😊1❤❤❤❤❤
@BhaiRayyanKiDuniya
@BhaiRayyanKiDuniya 2 года назад
Waiting for the video since two days. Thank you for it
@unboxtheuniverse5336
@unboxtheuniverse5336 2 года назад
Course kab khatam hoga bhaiya 😃😃 actually offline hogya college isliye poochaa 🤕 warna poora mazaaa aata he Lectures me ...
@codingindisguise
@codingindisguise Год назад
Thank You Bhaiyaaa!!, Now you are MY FAVOURITE on this platform!❤
@harpratapsinhnakoom3540
@harpratapsinhnakoom3540 2 года назад
dil se maja a raha hai bhaiya ... best course
@chiragyadav5467
@chiragyadav5467 Год назад
best explaination for merging of k sorted arrays and list 😍😍😍😍
@magangagan6535
@magangagan6535 Год назад
hats off bhaiya. thanks a lot for providing such top notch content.
@prashantbirajdar9271
@prashantbirajdar9271 2 года назад
wahh bhiyaa maza aa gya subkuch samaj bhi aya nice....
@BengoliInBangalore
@BengoliInBangalore 2 года назад
Hi, i am using java for all these questions. Now lets say in this question you asked to sort the array, in such case can we use the sort method provided by java or we need to use the trivial looping method for sorting
@9852963775aaa
@9852963775aaa 2 года назад
Thankyou bhaiya so much for this course
@nishankdeep3084
@nishankdeep3084 2 года назад
thank you bhaiya , consistency op bhiaya
@govindsharma7696
@govindsharma7696 2 года назад
Bhaiya maza agya video dekhke 😍
@cia4889
@cia4889 Год назад
Ques 2) Alternate approach without using heap vector merge2Arrays(vectorarr1, vector arr2) { vector ans; int n1=arr1.size(); int n2=arr2.size(); int i=0,j=0; while(i
@tarakmheta8856
@tarakmheta8856 10 месяцев назад
what is the time and space complexity of this approach??
@studygainer5482
@studygainer5482 Год назад
completed bhaiya tnku soooooo much for this handsome series
@focus.placement5589
@focus.placement5589 2 года назад
kya baat hai bhaiayaaa thanks a lot😍😍😍
@sailendrachettri8521
@sailendrachettri8521 2 года назад
Thank you Love Bhaiya 🎆
@The_Shubham_Soni
@The_Shubham_Soni Год назад
Quite complex codes today but uprading🤓
@adarshtiwari8637
@adarshtiwari8637 2 года назад
Waiting for the video since two days. Thank you for it ❤❤
@anuptewary3016
@anuptewary3016 2 года назад
Present bhaiya with lot's of love for you
@kumarvikash287
@kumarvikash287 Год назад
Thanks for this helpful lecture
@PRIYANSHUKUMAR-un9zu
@PRIYANSHUKUMAR-un9zu 2 года назад
Present bhaiya❤🔥
@sounaksaha1455
@sounaksaha1455 2 года назад
Professor Babbar is Back!!!
@KratosProton
@KratosProton 2 года назад
Great explaination
@ishashukla5263
@ishashukla5263 2 года назад
Thank you so much bhaiya!
@Anonymous_Coder
@Anonymous_Coder Год назад
Ques 2 : Alternate Approach without using HEAP. vector merge(vector &a , vector &b){ vector ans; int n = a.size(); int m = b.size(); int i = 0 , j=0; while(i
@prathamdwivedi106
@prathamdwivedi106 6 месяцев назад
To bina heap ke to jyade aacha hua na ? heap use karke n*klogk lag raha hai
@TechUprise-by-Jyoti
@TechUprise-by-Jyoti 2 года назад
Thank you so much bhaiya😇
@vaidanshkukreja8970
@vaidanshkukreja8970 2 года назад
#BELIEVEINBABBAR I saw that gonna be green screen from next videos QUALITY++ NOTE : ONE MORE THING PLEASE INCREASE YOUR MIC VOLUME MANY PEOPLE WANT THAT
@memorybyshubhammanitripath4368
@memorybyshubhammanitripath4368 2 года назад
Before 19 April i will catch your consistency 😁
@govindsuryavanshi6653
@govindsuryavanshi6653 11 месяцев назад
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exists on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇‍♂ Thanks you.
@harshit_pareek
@harshit_pareek 6 месяцев назад
why you are completing all dsa series one by one😂
@harshmaurya7639
@harshmaurya7639 2 месяца назад
@@harshit_pareek 🤣🤣i always see his comnents in alternate videos
@abhishektripathi3904
@abhishektripathi3904 8 месяцев назад
Another approach for problem 2: i) push all the elements in a resultant vector in any order ii) Apply heapify algorithm to convert the resultant array into a max heap iii) Apply heap sort on the the resultant array to get the sorted array. Code: class Solution { private: void heapify(vector&ans, int i, int n){ int largest = i; int left = 2*i+1; int right = 2*i+2; if(left < n && ans[largest] < ans[left]){ largest = left; } if(right < n && ans[largest] < ans[right]){ largest = right; } if(largest != i){ swap(ans[largest],ans[i]); heapify(ans, largest, n); } } void heapSort(vector&ans, int size){ while(size != 1){ swap(ans[0],ans[size-1]); size--; heapify(ans, 0, size); } } public: //Function to merge k sorted arrays. vector mergeKArrays(vector arr, int k) { if(k == 1) return {arr[0]}; //Egde case vectorans; for(int i = 0; i < k; i++){ for(int j = 0; j < k; j++){ ans.push_back(arr[i][j]); } } int n = k*k; for(int i = n/2-1; i >= 0; i--){ heapify(ans, i, n); } heapSort(ans, n); return ans; } }; T.C. :- O(n2) + O(n) for heapify + O(nlogn) for heap sort = O(n2) S.C. :- O(K * K) P.S. :- Thanks love bhaiya❤
@arijitdubey
@arijitdubey 25 дней назад
Bro I think the time complexity of your code will also be O(K^2 . Log K) only because you are forgetting that when you apply heap sort, the size of this vector would be K^2. Thus, you are basically doing the brute force approach only, that is, traversing the matrix and then putting all elements into a new vector then applying a sorting algorithm to it. Thus it is not the optimized approach. (Although the time complexity of brute force only differs by a factor of 2.)
@fazerugbrug439
@fazerugbrug439 2 года назад
loved it
@hollywoodmovies1094
@hollywoodmovies1094 2 года назад
awesome content ...
@BornHubisLive
@BornHubisLive Год назад
Thnaks a lot Bhaiya.....RESPECT++;
@VinodKumar-hm6do
@VinodKumar-hm6do 2 года назад
Amazing👍
@akankshapandey8316
@akankshapandey8316 2 года назад
Thanku Sir 🙏
@faang1485
@faang1485 2 года назад
Very helpful bhaiya
@muhammadsuleman8936
@muhammadsuleman8936 11 месяцев назад
Great lecture
@rachit_joshi
@rachit_joshi Месяц назад
Thank You So Much BHRATA SHREE !!!!!!!
@digambardiwakar9535
@digambardiwakar9535 2 года назад
Thanks bhaiya
@shubhambhardwaj8894
@shubhambhardwaj8894 2 года назад
Thank you :)
@BhaiRayyanKiDuniya
@BhaiRayyanKiDuniya 2 года назад
going to end up dSA course with lots of learnings
@yashasvic2429
@yashasvic2429 Год назад
Thanks bro👍
@adamyasharma_0135
@adamyasharma_0135 6 месяцев назад
very heapful video!
@adarshsingh-ds5sg
@adarshsingh-ds5sg Год назад
thanku bhaiya
@ujjwalpratap8729
@ujjwalpratap8729 2 года назад
Maje aagye sir aaj
@abhay.1926
@abhay.1926 2 года назад
Op bhaiya ♥️♥️
@pankaj3518
@pankaj3518 Год назад
Mast sir Ji
@harshkumar7686
@harshkumar7686 11 месяцев назад
Time Complexity bhi improve hui thi bhaiya Kth subarray sum mein kyonki sum wali array ko sort karne ke liye (n^2)*log n time lag raha tha aur is heap wale tarike mein hamne sirf n^2 mein kar diya
@sagnikmodak4178
@sagnikmodak4178 Год назад
thanks sir
@sjcreations2490
@sjcreations2490 2 года назад
Attendance marked bhaiya🙏👍
@mysticmuskan3529
@mysticmuskan3529 Год назад
Thanks sir
@musicascade4408
@musicascade4408 2 года назад
best best best!
@harshvardhansingh2272
@harshvardhansingh2272 Год назад
nice bhaiya👍
@RobinSingh-nf4oo
@RobinSingh-nf4oo Месяц назад
I'm pretty sure I'm going to crack big companies interview one day. Thank you bhaiya for such videos.
@keshavgambhir9894
@keshavgambhir9894 2 года назад
Present Bhaiya
@ajayvemuri7429
@ajayvemuri7429 Год назад
I have did like this, I have taken one answer list and Once i add any node to answer list, I am freeing that node from original lists. At the end i will be having answerlist in my hand after deleting the original lists. Which means i am using O(k) for priority queue, O(n*k) for answerlist but i am deleting original list which is of O(n*k). so final space is O(n*k) + O(k) - O(n*k) = O(k). Is this right way to do??
@063himanshumishra4
@063himanshumishra4 2 года назад
Bhaiya moj kr dii
@user-sh5sn3gs7k
@user-sh5sn3gs7k Год назад
First question mai 1st approach mai time complexity O(N^2) aayegi na?? Because ismme 2 loop hai, usske baad sort kiya hai, loop k andar thodina sort kiya hai..
@prateeksomani9239
@prateeksomani9239 Год назад
In Ques . 1 : why we inserted only first (k-1) element in the heap , we insert k element in the heap then process the heap for rest of the elements and then our ans is heap.top( ) ... pls explain
@shivography459
@shivography459 2 года назад
Bhaiya ❤️
@yashmunde8005
@yashmunde8005 9 месяцев назад
thanks and done
@sachinvarshney1227
@sachinvarshney1227 2 года назад
Consistency op❤️
@pahaljain9209
@pahaljain9209 Год назад
Present bhaiya
@BhaiRayyanKiDuniya
@BhaiRayyanKiDuniya 2 года назад
in this question you asked to sort the array, in such case can we use the sort method provided by java or we need to use the trivial looping method for sorting
@adamyasharma_0135
@adamyasharma_0135 6 месяцев назад
sort method
@kritikarawat2180
@kritikarawat2180 Год назад
This lecture was very easy to understand. Well explained.
@pratyushtripathi1728
@pratyushtripathi1728 10 месяцев назад
@naveensingh_0735
@naveensingh_0735 2 года назад
Thank you bhaiya I was just wondering ki kab aaega 😅😅
@NARUTOUZUMAKI-bk4nx
@NARUTOUZUMAKI-bk4nx 7 месяцев назад
Understood
@utkarshsingh1457
@utkarshsingh1457 2 года назад
maza aagya
@jericodcosta2049
@jericodcosta2049 2 года назад
Attendance marked ✔️
@codingwithmanish
@codingwithmanish 2 года назад
1st question by second approach T.C--O(n^2)
@alexmercer4276
@alexmercer4276 6 месяцев назад
In 2nd question how i automatically updating ?
@zohebahmad9633
@zohebahmad9633 2 года назад
Maybe I didn't understand from the previous video and am further confused here but, for the first question (Kth largest sum), why can't we just make a Max Heap, push all elements into the max heap (obv using the priority queue stl class), then pop from max heap till k, and return the top of the max heap?
@ADITYAKUMAR-tb4gm
@ADITYAKUMAR-tb4gm 2 года назад
for that space complexity would be O(n) while for min heap , only O(k) space required
@zohebahmad9633
@zohebahmad9633 2 года назад
@@ADITYAKUMAR-tb4gm ahaaa this is what happens when you coincidentally zone every time the professor reiterates that one important concept
@ayushsinha5512
@ayushsinha5512 6 месяцев назад
i tried it bro but time complexity would be n^3
@uttamkesarwani6143
@uttamkesarwani6143 2 года назад
We need Handwritten Notes rest of Lectures, It's really time savings. When we have to revise, then I think all of us use that beautiful Notes. Otherwise it again a long time to see video again.
@motivationshorts3721
@motivationshorts3721 2 года назад
+1
@lostexplorer7442
@lostexplorer7442 2 года назад
Kuch khud bhi karlo!!
@BhaiRayyanKiDuniya
@BhaiRayyanKiDuniya 2 года назад
#BELIEVEINBABBAR I saw that gonna be green screen from next videos QUALITY++
@Fam_Uus
@Fam_Uus 2 года назад
Thanks ++
@teenageworrior1634
@teenageworrior1634 2 года назад
Bhaiya baki lectures ke bhi handwritten notes daliye plz🙏
@shantanusingh2039
@shantanusingh2039 Месяц назад
Need the code links to be updated bhaiya , it was a cherry on the top
@sukhpreetsingh5200
@sukhpreetsingh5200 Год назад
present bhaiya
@sajibkumarroy9280
@sajibkumarroy9280 2 года назад
Present bro
@shantanu8880
@shantanu8880 Год назад
1st qs. Time complexity will be O(N^2. logN), N^2 for using 2 loops and log n for inserting / deleting values to/from minHeap .
@YashG2309
@YashG2309 11 месяцев назад
O(N^2 log(K))
@inter3988
@inter3988 3 месяца назад
study before comment
@vershitayadav7753
@vershitayadav7753 3 месяца назад
🎉🎉
@nona7372
@nona7372 2 года назад
Bhaiya present !!
@himanshuchaudhari3505
@himanshuchaudhari3505 9 месяцев назад
Can anyone explain me how has he written the compare class in min heap while solving the merge K sorted array problem
@dhruvabhattacharya
@dhruvabhattacharya 2 года назад
🔥🔥🔥
@shreya-ff7qv
@shreya-ff7qv Год назад
in last question humne sare links remove nhi h to usse traversing me problem nhi hogi anybody please explain????????
@rahulPandey-xt2ww
@rahulPandey-xt2ww 10 месяцев назад
If you are feeling difficult Love's code try to understand this one T(C)= O(K^2 * log(K)) s(c)=o(k) vector mergeKArrays(vector arr, int k) { vectorans; priority_queueminh; for(int i=0;i1) { minh.push({arr[row][1],row}); // Increment the index of the current row to move to the next element in the row. arr[row].erase(arr[row].begin()); } } return ans; }
@Viralmems_xyz
@Viralmems_xyz 10 месяцев назад
nice bro
@amaan1180
@amaan1180 10 месяцев назад
Bhai plz also provide merge linked list code in this format
@Mohitkumar-un1ix
@Mohitkumar-un1ix 9 месяцев назад
@@amaan1180 Node * mergeKLists(Node *arr[], int K){ if(K == 1) return arr[0]; for(int i = 1; i < K ; i++){ Node* ord = new Node(-1); Node* tail = ord; Node* left = arr[i - 1]; Node* right = arr[i]; while(left && right){ if(left->data < right->data){ tail->next = left; tail = left; left = left->next; } else{ tail->next = right; tail = right; right = right->next; } } while(left){ tail->next = left; tail = left; left = left->next; } while(right){ tail->next = right; tail = right; right = right->next; } arr[i] = ord->next; } return arr[K - 1]; }
@user-gd8du8mo9c
@user-gd8du8mo9c 9 месяцев назад
Please add subtitles it is so much more helpful for South Indians when you are explaining
@itskaaryan7
@itskaaryan7 Год назад
when do we need to use the custom comparator in heap??
@ajinkyakale4391
@ajinkyakale4391 Год назад
When we need to store the elements in heap in a very particular order other than ascending or descending.
@9-1939
@9-1939 9 месяцев назад
🔥👌
@inter3988
@inter3988 3 месяца назад
after doing second problem, the last one was toooo easy
@surajshaw5880
@surajshaw5880 Год назад
Consistency is the key of success 😊
@lalitk
@lalitk Год назад
Yes
@royalenfieldmeteorrider7873
@royalenfieldmeteorrider7873 2 года назад
Good
Далее
Lecture 77: Heaps Hard Interview Questions || Part - 3
1:05:15
Stack vs Heap Memory - Simple Explanation
5:28
Просмотров 212 тыс.
Github - You Can View Deleted Private Fork Data
23:40
Why The Windows Phone Failed
24:08
Просмотров 194 тыс.
Arm PC Build (Rock 5 ITX)
22:35
Просмотров 66 тыс.
Coding Interviews Be Like
5:31
Просмотров 6 млн