Merge K sorted Lists - Solution | Hashmap and Heap | Data Structure and Algorithms in JAVA

Поділитися
Вставка
  • Опубліковано 16 лис 2024

КОМЕНТАРІ • 107

  • @subhammahanta3433
    @subhammahanta3433 2 роки тому +16

    We need more teachers like you sir...!!(Who will never let the students get bored)......agar ese teacher mil gaye to India a future bright h

    • @Pepcoding
      @Pepcoding  2 роки тому +2

      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

    • @a.techsys9389
      @a.techsys9389 2 роки тому +1

      @subham right brother.

  • @aasheesh6001
    @aasheesh6001 Рік тому +4

    Bro dropped the best explanation for priority Queue and think we won't notice.

  • @sanatasneem2674
    @sanatasneem2674 2 роки тому +1

    This is some whole other level 😲😲😲😲
    Kabhi socha bhi nahi hoga ki ayese bhi koi samjha sakta hai!

  • @sauravdas7591
    @sauravdas7591 3 роки тому +29

    is it only me, or the audio sounds a bit jittery? very light distortion in audio

  • @MYSTERIOUS_BOY_1
    @MYSTERIOUS_BOY_1 11 місяців тому

    The best.......................sir❤
    Literally NO WORDS...😮 FOR YOUR EXPLAINATION ❤

  • @rohankaran0079
    @rohankaran0079 2 роки тому

    Sir ap bhagvan hai aise koi samjha hi nai skta hai
    No content is upto this level in any platform for DSA i bet

  • @itachiuchiha-vs3qb
    @itachiuchiha-vs3qb 2 роки тому +1

    WOW! your way of implementing code with explaining clear thought process is legendary. .

  • @somnathroy6251
    @somnathroy6251 2 роки тому +1

    Man this is so good, I regret founding this channel so late.

    • @Pepcoding
      @Pepcoding  2 роки тому +2

      Hope we help you but for better experience and well organised content visit - nados.io 🚀
      ⚠️ You can also post your queries on community tab.

  • @namantiwari8251
    @namantiwari8251 2 роки тому +1

    That's Mind Blowing 💯💯

  • @sharuk3545
    @sharuk3545 3 роки тому +1

    next level explanation with the help of this solution i did it merge K LinkedList problem

  • @pramodbasu7732
    @pramodbasu7732 Рік тому +1

    5 days back this question was asked to me in VMWARE coding round

  • @aayush481
    @aayush481 2 роки тому +1

    epic man, no one tells how internally comareTo works !

  • @sonipra2376
    @sonipra2376 3 роки тому +3

    Splendid Explanation.

    • @Pepcoding
      @Pepcoding  3 роки тому

      Thankyou beta!
      I am glad you liked it. If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @rishabhgoyal2835
    @rishabhgoyal2835 4 роки тому +9

    next level explanation , thank you : )

    • @Pepcoding
      @Pepcoding  4 роки тому +1

      Thank you so much. Keep learning

  • @mihirsaini592
    @mihirsaini592 Рік тому

    Great explanation as always.

  • @mickyman753
    @mickyman753 3 роки тому +1

    instead or writing comparator or comparable ,use this
    PriorityQueue pq=new PriorityQueue((p,q)->{
    return p.val-q.val;
    });

  • @chandrashekharagrawal4890
    @chandrashekharagrawal4890 2 роки тому

    Woww, this is amazing.

  • @ashwinnema06
    @ashwinnema06 2 роки тому

    Nice explanation sir

  • @pranshulkharniwal8146
    @pranshulkharniwal8146 3 роки тому +1

    majha aa gya sir✨✨✨✨

    • @Pepcoding
      @Pepcoding  3 роки тому

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @anirudhatalmale5575
    @anirudhatalmale5575 3 роки тому +1

    very well explained

    • @Pepcoding
      @Pepcoding  3 роки тому

      Glad you think so and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @samirray7544
    @samirray7544 4 роки тому

    understood it very well.......very informative video...........

    • @Pepcoding
      @Pepcoding  3 роки тому

      Thankyou beta!
      I am glad you liked it. I also hope that you are watching till end.
      Will you like to write a few words about us here (www.quora.com/Which-is-the-best-online-course-to-learn-data-structures)

    • @samirray7544
      @samirray7544 3 роки тому

      @@Pepcoding Sir it says page not found

  • @ghanibhai1630
    @ghanibhai1630 3 роки тому

    i have used hashmap + priority queue

  • @nextgeneration2835
    @nextgeneration2835 4 роки тому +2

    just to the point :) thank you

  • @shrad6611
    @shrad6611 3 роки тому

    pure content video
    sirf kaam ki chize karte ho aur logo ki tarah bakwas nahi
    luv the video

    • @Pepcoding
      @Pepcoding  3 роки тому

      Thankyou beta!
      I am glad. Your kind words are the kind of motivation that truly help me in making more and more content. Especially, these days, not everybody is generous with motivating anybody either. It means a lot.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
      Keep learning and keep loving Pepcoding😊

    • @shrad6611
      @shrad6611 3 роки тому

      @@Pepcoding yeah sure

  • @jsuryakt
    @jsuryakt 2 роки тому

    awesome explanation

    • @Pepcoding
      @Pepcoding  2 роки тому

      Glad it was helpful!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @mehulbisht9708
    @mehulbisht9708 4 роки тому +2

    sir to implement an interface in java in android studio we need to annotate the function ( which is declared inside interface ) with @override.
    Isn't that required for java programs outside android studio ?

    • @Pepcoding
      @Pepcoding  4 роки тому +5

      @override is not mandatory beta. Not even in android.

    • @mehulbisht9708
      @mehulbisht9708 4 роки тому

      @@Pepcoding ok thankyou sir

  • @RishabhJain-hr6sz
    @RishabhJain-hr6sz 3 роки тому

    Sir, not able to find fractional knapsack problem on channel. Could you please share the link, since you mentioned in this video. Thanks!

  • @factsstats3959
    @factsstats3959 Рік тому

    Can't we just store all values in the Prority Queue First and remove them one by one and print them while removing?

  • @abhishekvishwakarma9045
    @abhishekvishwakarma9045 3 роки тому

    Great Explanation sir get multiple topics (Interface) also 👌🔥

    • @Pepcoding
      @Pepcoding  3 роки тому +2

      Glad to know that you liked the content and thank you for appreciating. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc

  • @utkarshsharma1185
    @utkarshsharma1185 2 роки тому

    thanks sir...

  • @shreeyagupta8472
    @shreeyagupta8472 3 роки тому +2

    Sir what if we add all the elements of all the arrays in priority queue and then peek and remove them all?

    • @1piecegaming622
      @1piecegaming622 3 роки тому

      hey..are you following the babbar bhaiya DSA sheet??

    • @NitinSharma-bk7dw
      @NitinSharma-bk7dw 3 роки тому +3

      Complexity will be high if you do so because inserting an element in pq takes log(n). For k^2 element it will be k^2 log k + k^2 iterations for inserting in pq

  • @gauravagarwal6565
    @gauravagarwal6565 3 роки тому

    what about :
    for(int i = 0;i

    • @bloody9162
      @bloody9162 2 роки тому

      TC: nlogn where n is the length of all lists combined, using heaps/pq tc gets reduced to nlogk where k is the size of lists array

  • @nishantchaudhary7902
    @nishantchaudhary7902 2 роки тому

    can anyone please give me the link of fractional knapsak i'm unable to find it..

  • @deepakjoshi4318
    @deepakjoshi4318 3 роки тому

    Sir Fractional knapsack ki video nhi dali hai apne?

  • @VISHNUVardhan-mr2cq
    @VISHNUVardhan-mr2cq 4 роки тому +1

    Sir, u have not uploaded fractional knapsack?

  • @abhishekjaswal4415
    @abhishekjaswal4415 3 роки тому +1

    what if we add all the elements into a priority queue and simply remove elements from priority queue and just return it
    its working for me
    but I guess the time complexity will increase?is it?

    • @himanshumishra8181
      @himanshumishra8181 3 роки тому

      Nah not sure about the time complexity but the space complexity is goona get O(sum of size of all arrays ) compared to O(k)

    • @Pepcoding
      @Pepcoding  3 роки тому

      Visit - nados.pepcoding.com and sign up to NADOS.
      You can ask your doubts on community tab. There are lots of programmers and mentors who can help you out with such doubts.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @ankitparashar8730
    @ankitparashar8730 3 роки тому

    Explanation level

    • @Pepcoding
      @Pepcoding  3 роки тому

      If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @runtime379
    @runtime379 3 роки тому

    great sir

  • @animetimes5563
    @animetimes5563 3 роки тому

    OP level explanation

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Glad to know, that you love the explanation, for better experience and precisely arranged videos.
      Visit - nados.pepcoding.com and sign up to NADOS.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @hymnish_you
    @hymnish_you 4 роки тому

    Sir, why didn't u use this simple method?
    public static ArrayList mergeKSortedLists(ArrayList lists){
    PriorityQueue pq = new PriorityQueue();
    for(ArrayList ls : lists){
    for(int num : ls){
    pq.offer(num);
    }
    }
    ArrayList rv = new ArrayList();
    while(pq.size() != 0){
    rv.add(pq.poll());
    }
    return rv;
    }

  • @RishabhJain-hr6sz
    @RishabhJain-hr6sz 3 роки тому

    Amazing!

  • @RiteshKumar-nt5sj
    @RiteshKumar-nt5sj 3 роки тому

    compare to k andar pair other kya h? this to pair class ka value hai but other?
    \

    • @Pepcoding
      @Pepcoding  3 роки тому

      For clearing all your doubts and for best experience, visit on nados.pepcoding.com
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @surajpatil2879
    @surajpatil2879 3 роки тому

    PriorityQueue pq = new PriorityQueue();
    for(int i=0;i

  • @satvrii
    @satvrii Рік тому

  • @akshatbhaskar5711
    @akshatbhaskar5711 2 роки тому

    Can anyone please help me telling that what will be complexities of this solution? Btw best video

  • @abhishekverma-se6vw
    @abhishekverma-se6vw 4 роки тому +1

    Sir when are you uploading level up?

  • @hungryhunter6210
    @hungryhunter6210 4 роки тому +1

    Sir C++ mein objects ki priority queue k liye comparable kaise likhte hai?

    • @Pepcoding
      @Pepcoding  4 роки тому

      wahan operator overloading ek rasta hai, doosra functor hota hai. Operator overloading is the usual way.

    • @hungryhunter6210
      @hungryhunter6210 4 роки тому

      Thank you for the reply sir.

    • @umangchhabra9678
      @umangchhabra9678 4 роки тому +2

      class Pair
      {
      public:
      int li;
      int di;
      int data;
      Pair(int li,int di,int data)
      {
      this->li=li;
      this->di=di;
      this->data=data;
      }
      };
      class FunctorCompare
      {
      public:
      bool operator()(Pair a,Pair b)
      {
      return a.data>b.data;
      }
      };
      priority_queue pq;

    • @shubhamsood1406
      @shubhamsood1406 4 роки тому +1

      @@umangchhabra9678 Can you share your C++ code for this question, I wrote a code but it is not working bcoz of some errors

  • @ashishm8850
    @ashishm8850 3 роки тому

    Unda!

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Thankyou beta!
      Keep learning and keep watching😊

  • @satyam18_
    @satyam18_ 4 роки тому

    Sir cant we simply add all list in a priority queue and then print the priority queue ??

    • @Pepcoding
      @Pepcoding  4 роки тому +3

      space jyada lag jaega. O(k) space allowed tha

  • @amandixit3555
    @amandixit3555 4 роки тому +1

    public static ArrayList mergeKSortedLists(ArrayList list)
    {
    ArrayList rv = new ArrayList();
    PriorityQueue pq=new PriorityQueue();
    for(int i=0;i0)
    {
    rv.add(pq.remove());
    }
    return rv;
    }
    sir can we do like this.

  • @prakritidevverma4315
    @prakritidevverma4315 3 роки тому

    Can we do all this in O(1) memory ?

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

    • @prakritidevverma4315
      @prakritidevverma4315 3 роки тому

      @@Pepcoding cool, I'll ask over there.

  • @indranilchakraborty5949
    @indranilchakraborty5949 3 роки тому

    Sir fractional knapsack ka vedio nhi hai pepcoding ka ....

    • @sauravdas7591
      @sauravdas7591 3 роки тому

      aditya verma ka dekh lo video

    • @raviashwin1157
      @raviashwin1157 3 роки тому

      @@sauravdas7591 fractional greedy se hota hai wo nahi padhaya aditya verma ne

  • @yelp9359
    @yelp9359 4 роки тому

    Sir iski complexity kya hogi?

    • @Pepcoding
      @Pepcoding  4 роки тому +1

      nlogk

    • @hdang1997
      @hdang1997 4 роки тому

      @@Pepcoding where n is total number of elements in all the arrays, correct?

    • @namanmittal9403
      @namanmittal9403 3 роки тому

      @@hdang1997 where n is the number of elements in the longest list and logk is for the priority queue (enque/deque)
      ignoring the number of list i.e since k

  • @varunsde9533
    @varunsde9533 3 роки тому

    I have solved this by using stream API in Java 8
    ArrayList result = lists.stream.flatMap(x->x.stream()).sorted.collect(Collectors.toCollection(ArrayList::new));

  • @imavij12
    @imavij12 2 роки тому

    Ye other ki value kaha se aa rhi h. Compare this ko kis se karega samajh nahi aa rha

    • @Pepcoding
      @Pepcoding  2 роки тому

      For better insight, visit nados.pepcoding.com, post your doubts, community will help you out there.

  • @creativegiant148
    @creativegiant148 3 роки тому +1

    It is bfs
    Kindoff

  • @ayushgoel9584
    @ayushgoel9584 4 роки тому

    sir heaps ke questions mein confidence nhi aaya, i hope we will do atleast 20 more problems in LU+IP

    • @Pepcoding
      @Pepcoding  4 роки тому

      we have a lot many in lu + ip. i think 100 ke kareeb hain, hashmap aur heaps mila ke

  • @sarfinawalksh503
    @sarfinawalksh503 4 роки тому

    Sir, u have not uploaded fractional knapsack?

    • @Pepcoding
      @Pepcoding  4 роки тому

      hanji beta, hashmap-heaps ke liye chodda tha firr choot he gya. karna hai

    • @sarfinawalksh503
      @sarfinawalksh503 4 роки тому

      @@Pepcoding ok sir