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

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

Пікірлер: 213

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

  • @harsh4638
    @harsh46382 жыл бұрын

    Ek or puree youtube ka sabse best lecture

  • @vishalmangla1832
    @vishalmangla1832 Жыл бұрын

    if today i get the job its because love bhaiya .you are such an amazing mentor i have ever seen.

  • @challengeAceiver
    @challengeAceiver Жыл бұрын

    Overdose hogaya bhaiya😂😂. Lekin usi baat ke to package hai. Btw jordar content bhaiya, jitni tareef karu utni kamm hai

  • @parthsharma5966
    @parthsharma59662 жыл бұрын

    consistency dono ka high hai bhaiya.... thanks

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya Жыл бұрын

    Waiting for the video since two days. Thank you for it

  • @vaibhavagarwal5367
    @vaibhavagarwal5367 Жыл бұрын

    Thanks for this helpful lecture i am salute you for your consistency and i also try my best to be consistent

  • @aakashbhargavaa
    @aakashbhargavaa2 жыл бұрын

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

  • @neerajgarg9096
    @neerajgarg90962 жыл бұрын

    *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

  • @priyanshkumariitd

    @priyanshkumariitd

    4 ай бұрын

    Yes T.C. of heap solution is O(n^2 . log(k))

  • @codingindisguise
    @codingindisguise Жыл бұрын

    Thank You Bhaiyaaa!!, Now you are MY FAVOURITE on this platform!❤

  • @harpratapsinhnakoom3540
    @harpratapsinhnakoom35402 жыл бұрын

    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
    @prashantbirajdar92712 жыл бұрын

    wahh bhiyaa maza aa gya subkuch samaj bhi aya nice....

  • @9852963775aaa
    @9852963775aaa2 жыл бұрын

    Thankyou bhaiya so much for this course

  • @focus.placement5589
    @focus.placement55892 жыл бұрын

    kya baat hai bhaiayaaa thanks a lot😍😍😍

  • @govindsharma7696
    @govindsharma76962 жыл бұрын

    Bhaiya maza agya video dekhke 😍

  • @studygainer5482
    @studygainer5482 Жыл бұрын

    completed bhaiya tnku soooooo much for this handsome series

  • @sailendrachettri8521
    @sailendrachettri8521 Жыл бұрын

    Thank you Love Bhaiya 🎆

  • @nishankdeep3084
    @nishankdeep30842 жыл бұрын

    thank you bhaiya , consistency op bhiaya

  • @kumarvikash287
    @kumarvikash287 Жыл бұрын

    Thanks for this helpful lecture

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

  • @vaidanshkukreja8970
    @vaidanshkukreja89702 жыл бұрын

    #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

  • @anuptewary3016
    @anuptewary30162 жыл бұрын

    Present bhaiya with lot's of love for you

  • @The_Shubham_Soni
    @The_Shubham_Soni Жыл бұрын

    Quite complex codes today but uprading🤓

  • @ishashukla5263
    @ishashukla52632 жыл бұрын

    Thank you so much bhaiya!

  • @adarshtiwari8637
    @adarshtiwari86372 жыл бұрын

    Waiting for the video since two days. Thank you for it ❤❤

  • @ky747r0
    @ky747r02 жыл бұрын

    Great explaination

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

    9 ай бұрын

    what is the time and space complexity of this approach??

  • @PRIYANSHUKUMAR-un9zu
    @PRIYANSHUKUMAR-un9zu2 жыл бұрын

    Present bhaiya❤🔥

  • @faang1485
    @faang14852 жыл бұрын

    Very helpful bhaiya

  • @TechUprise-by-Jyoti
    @TechUprise-by-Jyoti2 жыл бұрын

    Thank you so much bhaiya😇

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l3 ай бұрын

    Thank you bhaiya

  • @hollywoodmovies1094
    @hollywoodmovies10942 жыл бұрын

    awesome content ...

  • @abhishektripathi3904
    @abhishektripathi39047 ай бұрын

    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 largest = left; } if(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 for(int j = 0; 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

    5 күн бұрын

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

  • @codingwithmanish
    @codingwithmanish2 жыл бұрын

    1st question by second approach T.C--O(n^2)

  • @rahulPandey-xt2ww
    @rahulPandey-xt2ww9 ай бұрын

    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

    9 ай бұрын

    nice bro

  • @amaan1180

    @amaan1180

    9 ай бұрын

    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 Node* ord = new Node(-1); Node* tail = ord; Node* left = arr[i - 1]; Node* right = arr[i]; while(left && right){ if(left->data 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]; }

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya Жыл бұрын

    going to end up dSA course with lots of learnings

  • @akankshapandey8316
    @akankshapandey83162 жыл бұрын

    Thanku Sir 🙏

  • @BornHubisLive
    @BornHubisLive Жыл бұрын

    Thnaks a lot Bhaiya.....RESPECT++;

  • @unboxtheuniverse5336
    @unboxtheuniverse53362 жыл бұрын

    Course kab khatam hoga bhaiya 😃😃 actually offline hogya college isliye poochaa 🤕 warna poora mazaaa aata he Lectures me ...

  • @rachit_joshi
    @rachit_joshiАй бұрын

    Thank You So Much BHRATA SHREE !!!!!!!

  • @sounaksaha1455
    @sounaksaha14552 жыл бұрын

    Professor Babbar is Back!!!

  • @adamyasharma_0135
    @adamyasharma_01356 ай бұрын

    very heapful video!

  • @muhammadsuleman8936
    @muhammadsuleman893610 ай бұрын

    Great lecture

  • @shubhambhardwaj8894
    @shubhambhardwaj88942 жыл бұрын

    Thank you :)

  • @fazerugbrug439
    @fazerugbrug4392 жыл бұрын

    loved it

  • @pahaljain9209
    @pahaljain9209 Жыл бұрын

    Present bhaiya

  • @BengoliInBangalore
    @BengoliInBangalore2 жыл бұрын

    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

  • @memorybyshubhammanitripath4368
    @memorybyshubhammanitripath43682 жыл бұрын

    Before 19 April i will catch your consistency 😁

  • @VinodKumar-hm6do
    @VinodKumar-hm6do2 жыл бұрын

    Amazing👍

  • @yashasvic2429
    @yashasvic2429 Жыл бұрын

    Thanks bro👍

  • @pankaj3518
    @pankaj3518 Жыл бұрын

    Mast sir Ji

  • @ujjwalpratap8729
    @ujjwalpratap87292 жыл бұрын

    Maje aagye sir aaj

  • @RobinSingh-nf4oo
    @RobinSingh-nf4ooАй бұрын

    I'm pretty sure I'm going to crack big companies interview one day. Thank you bhaiya for such videos.

  • @adarshsingh-ds5sg
    @adarshsingh-ds5sg Жыл бұрын

    thanku bhaiya

  • @govindsuryavanshi6653
    @govindsuryavanshi665310 ай бұрын

    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

    Ай бұрын

    @@harshit_pareek 🤣🤣i always see his comnents in alternate videos

  • @yashmunde8005
    @yashmunde80058 ай бұрын

    thanks and done

  • @sagnikmodak4178
    @sagnikmodak4178 Жыл бұрын

    thanks sir

  • @jericodcosta2049
    @jericodcosta20492 жыл бұрын

    Attendance marked ✔️

  • @mysticmuskan3529
    @mysticmuskan3529 Жыл бұрын

    Thanks sir

  • @keshavgambhir9894
    @keshavgambhir98942 жыл бұрын

    Present Bhaiya

  • @abhay.1926
    @abhay.19262 жыл бұрын

    Op bhaiya ♥️♥️

  • @sjcreations2490
    @sjcreations24902 жыл бұрын

    Attendance marked bhaiya🙏👍

  • @harshvardhansingh2272
    @harshvardhansingh2272 Жыл бұрын

    nice bhaiya👍

  • @063himanshumishra4
    @063himanshumishra42 жыл бұрын

    Bhaiya moj kr dii

  • @harshkumar7686
    @harshkumar768610 ай бұрын

    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

  • @NARUTOUZUMAKI-bk4nx
    @NARUTOUZUMAKI-bk4nx6 ай бұрын

    Understood

  • @sachinvarshney1227
    @sachinvarshney12272 жыл бұрын

    Consistency op❤️

  • @naveensingh_0735
    @naveensingh_07352 жыл бұрын

    Thank you bhaiya I was just wondering ki kab aaega 😅😅

  • @kritikarawat2180
    @kritikarawat2180 Жыл бұрын

    This lecture was very easy to understand. Well explained.

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Жыл бұрын

    present bhaiya

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

  • @musicascade4408
    @musicascade44082 жыл бұрын

    best best best!

  • @user-gd8du8mo9c
    @user-gd8du8mo9c8 ай бұрын

    Please add subtitles it is so much more helpful for South Indians when you are explaining

  • @inter3988
    @inter39882 ай бұрын

    after doing second problem, the last one was toooo easy

  • @shivography459
    @shivography4592 жыл бұрын

    Bhaiya ❤️

  • @yutubegaming5340
    @yutubegaming5340Ай бұрын

    T C of q1 using min heap is O(n^2 logk)

  • @utkarshsingh1457
    @utkarshsingh14572 жыл бұрын

    maza aagya

  • @shantanu8880
    @shantanu888011 ай бұрын

    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

    2 ай бұрын

    study before comment

  • @pratyushtripathi1728
    @pratyushtripathi17289 ай бұрын

  • @Fam_Uus
    @Fam_Uus2 жыл бұрын

    Thanks ++

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya Жыл бұрын

    #BELIEVEINBABBAR I saw that gonna be green screen from next videos QUALITY++

  • @sajibkumarroy9280
    @sajibkumarroy92802 жыл бұрын

    Present bro

  • @ajayvemuri7429
    @ajayvemuri742911 ай бұрын

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

  • @nona7372
    @nona73722 жыл бұрын

    Bhaiya present !!

  • @uttamkesarwani6143
    @uttamkesarwani61432 жыл бұрын

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

  • @vershitayadav7753
    @vershitayadav77532 ай бұрын

    🎉🎉

  • @shresthkaushik6636
    @shresthkaushik6636 Жыл бұрын

    🙏🙏🙏

  • @dhruvabhattacharya
    @dhruvabhattacharya2 жыл бұрын

    🔥🔥🔥

  • @surajshaw5880
    @surajshaw5880 Жыл бұрын

    Consistency is the key of success 😊

  • @lalitk

    @lalitk

    Жыл бұрын

    Yes

  • @royalenfieldmeteorrider7873
    @royalenfieldmeteorrider78732 жыл бұрын

    Good

  • @shantanusingh2039
    @shantanusingh203920 күн бұрын

    Need the code links to be updated bhaiya , it was a cherry on the top

  • @jiveshanand5948
    @jiveshanand5948 Жыл бұрын

    completed

  • @utkarshpatidar167
    @utkarshpatidar167 Жыл бұрын

    🔥

  • @puneetgupta6398
    @puneetgupta63982 жыл бұрын

    🔥🔥🔥🔥

  • @9-1939
    @9-19398 ай бұрын

    🔥👌

  • @satyamjha-codeindwala6666
    @satyamjha-codeindwala666610 ай бұрын

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

  • @BhaiRayyanKiDuniya
    @BhaiRayyanKiDuniya Жыл бұрын

    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

  • @pawankumaryadav8127
    @pawankumaryadav812710 ай бұрын

    concept+++