Activity Selection Problem - Greedy Algorithm | C++ Placement Course | Lecture 33.3

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 พ.ย. 2024

ความคิดเห็น • 80

  • @learningoverflow3138
    @learningoverflow3138 3 ปีที่แล้ว +8

    we can just save the end first and then start and then use normal sort function
    for(int i=0;i>start>>end;
    v.push_back({end,start});
    }
    sort(v.begin(),v.end());
    please correct me if i am wrong

  • @birdtech9816
    @birdtech9816 2 ปีที่แล้ว +1

    kya solution he sir, mja aa gya

  • @unemployedcse3514
    @unemployedcse3514 11 หลายเดือนก่อน +1

    Awesome ❤

  • @shivjyotigarai2141
    @shivjyotigarai2141 3 ปีที่แล้ว +4

    In 1:33 , the output should be 1 rather than 2. Its said that "Start time of one chosen meeting can't be equal to the end time of the other chosen meeting."

    • @nitigyajoshi4658
      @nitigyajoshi4658 3 ปีที่แล้ว +1

      yaha pe constraints different hai gfg se.

    • @shivjyotigarai2141
      @shivjyotigarai2141 3 ปีที่แล้ว

      @@nitigyajoshi4658 constraints??

    • @nitigyajoshi4658
      @nitigyajoshi4658 3 ปีที่แล้ว

      @@shivjyotigarai2141 constraints ka matlab nahi pata?

    • @shivjyotigarai2141
      @shivjyotigarai2141 3 ปีที่แล้ว

      @@nitigyajoshi4658 haan. lekin usse iska kya connection haan?

  • @tanvi6399
    @tanvi6399 3 ปีที่แล้ว +3

    Thank u bhaiya 💕💕

  • @sameerraj5800
    @sameerraj5800 3 ปีที่แล้ว +9

    Rather than making a custom comparator just use vectors of pair and fill end time before the start and simply use the sort function.

    • @krishnakantupadhyay3053
      @krishnakantupadhyay3053 2 ปีที่แล้ว +4

      avoid doing this because usually you are not asked to write the entire code(where you'll be taking input and writing the main function) instead you'll just have to write the logic part in that case either you've to make another 2d vector and run a loop to store the end time first or you can use comaparator function, In first case you'll be using extra space that's why comaprator function is used for sorting

    • @yashvats824
      @yashvats824 2 ปีที่แล้ว

      @@krishnakantupadhyay3053 No dear,
      ll n;
      cin >> n;
      vector a(n);
      fori(0, n)
      {
      cin >> a[i].second >> a[i].first;
      }
      sort(a.begin(), a.end());
      int ans = 0;
      int pe = -1;
      fori(0, n)
      {
      if (pe

  • @AryanSharma-zl7jf
    @AryanSharma-zl7jf 2 ปีที่แล้ว +16

    anyone else with me who vibes on initial background music of apna college 😂😂😂

  • @utkarshgautam1940
    @utkarshgautam1940 3 ปีที่แล้ว +6

    how this guy is even teaching,leave it man,not for u ,just blindly reading code

  • @anoopsaxena1861
    @anoopsaxena1861 3 ปีที่แล้ว +4

    I sorted by end-start time, and then use the same concept as if( end

    • @spaghetti185
      @spaghetti185 2 ปีที่แล้ว +2

      That was my first thought as well but I think it won't give the correct answer everytime. I'll attempt at giving the reason coz I'm also not sure:
      Why are you and me thinking about sorting by duration? That's because we think if we fill the allowed time with activities that require less amount of time then the number of activities will be maximum but if you look closely, we are assuming that we can start any activity at any time, which is not the case!
      Suppose, you are at t=10, and you have two options right now, either activity A1 with start=15, end=18 and another activity A2 with start=10, end=16.
      Now, if A1 is selected (since it has less duration) then it will occupy till t=18 and only then we'll be able to start any other activity. Whereas, if we choose A2 then it will be done till t=16!! And we can start another activity right away!
      Here, A1 is essentially behaving like it had start=10, end=18
      Therefore, choosing A2 and thus, the activity with earlier end time is preferenced.

    • @abhishekranjan320
      @abhishekranjan320 11 หลายเดือนก่อน

      thanks @@spaghetti185

  • @arpit35007
    @arpit35007 3 ปีที่แล้ว +3

    Please share similar problems as well.

  • @sahajpatel2749
    @sahajpatel2749 3 ปีที่แล้ว +4

    jaldi se jaldi leni hai jo jaldi khatam ho rhi hai 😆 3:46

  • @thecaptaman4027
    @thecaptaman4027 3 ปีที่แล้ว +2

    Web development ka course continue nhi ho rha aur c++ ka course khatm nhi ho rha

  • @kingsukrudra2997
    @kingsukrudra2997 3 ปีที่แล้ว

    Thank you

  • @sonalirawat6253
    @sonalirawat6253 5 หลายเดือนก่อน

    where is job selelction problem

  • @avirajarora1476
    @avirajarora1476 3 ปีที่แล้ว

    Thankyou bhaiya.

  • @upasanapan8210
    @upasanapan8210 3 ปีที่แล้ว +1

    custom operator wala trick thick se samajh nhi aa rha hai

  • @vinaytamta7958
    @vinaytamta7958 3 ปีที่แล้ว +2

    0:01 Heard Ok Google? 😂😁

  • @VAIBHAVMALHOTRA19
    @VAIBHAVMALHOTRA19 ปีที่แล้ว +1

    Am I the only one who was dancing on those intro beats?

  • @manishmalhotra5387
    @manishmalhotra5387 3 ปีที่แล้ว

    Can be suggest this approach is correct or not.
    Pseudo code
    Take vector of pair
    Sort with their starting time
    Prevend=vector.second
    Take=1
    Loop(1->n)
    If vector.first >=Prevend then
    Take++
    Prevend=vector.second.
    Basically my logic is that choose those activity which start first and you can choose those activity whose starting time is equal or more than ending time of previous activity.

    • @kanishkbisht5461
      @kanishkbisht5461 3 ปีที่แล้ว +2

      the thing is that the activity can start early but may take too much time & so end late. Then your algo will fail.
      We want to maximize no. of jobs done in a given time frame.

  • @albinthomas9737
    @albinthomas9737 3 ปีที่แล้ว +1

    Bhai jaldi karna hai toh difference between start and end time kyo nahi dekhte hai joh kaam chota hoga usee jyaada hopayenge na kaam?????🙏

    • @tarunbisht8016
      @tarunbisht8016 3 ปีที่แล้ว

      activity which have less end time will have less difference offcourse.

    • @avronilbanerjee5302
      @avronilbanerjee5302 2 ปีที่แล้ว +1

      @@tarunbisht8016 no not at all

  • @GouravKumar-zk5cw
    @GouravKumar-zk5cw 3 ปีที่แล้ว

    Web dev course kab continue hoga

  • @adarshraj6721
    @adarshraj6721 3 ปีที่แล้ว

    typedef pair pair1;
    struct comp {
    bool operator()(const pair1 &x, const pair1 &y) const {
    if (x.second != y.second) {
    return x.second < y.second;
    }
    return x.first < y.first;
    }
    };
    int Solution::solve(vector &A, vector &B) {
    vectorarr;
    for(int i=0;i

  • @MANPREETSINGH-ft9hd
    @MANPREETSINGH-ft9hd 3 ปีที่แล้ว

    why we are using a[1] and b[1] in comparator, not a[0] and b[0] please someone explain.

    • @dankaxon4230
      @dankaxon4230 3 ปีที่แล้ว +3

      bhai end time se sort kar rahe hai

  • @23ritik
    @23ritik 3 ปีที่แล้ว +2

    Upcoming premier are khatarnak 🤩🤩but i want to learn theae in java only please explain java code also

    • @nareshsharma590
      @nareshsharma590 3 ปีที่แล้ว

      For Java - Refer to pepcoding on TH-cam , it has complete DSA and questions explained in java

  • @lakshyanawandhar6768
    @lakshyanawandhar6768 3 ปีที่แล้ว

    Plz explain sort line

  • @saurabhjoshi640
    @saurabhjoshi640 2 ปีที่แล้ว

    ohh physics wala🤨

  • @BeingEntertained
    @BeingEntertained 3 ปีที่แล้ว

    yeh a[1]

  • @adarshraj6721
    @adarshraj6721 3 ปีที่แล้ว +1

    I was solving the same q today

  • @sakshamsharma5484
    @sakshamsharma5484 2 ปีที่แล้ว +1

    Kudh ko hi samja rahe ho kya

  • @abhishekrajora8933
    @abhishekrajora8933 2 ปีที่แล้ว

    sorry it was a right code it's my mistaken

  • @LearnCodeHS
    @LearnCodeHS 2 ปีที่แล้ว +3

    bhai tu padhana chod de..

  • @job_freak
    @job_freak 3 ปีที่แล้ว +10

    Bhai samjha toh deta

    • @atishayist
      @atishayist 3 ปีที่แล้ว +2

      bhai isse zyada kya smjhayenge vo?

    • @nitigyajoshi4658
      @nitigyajoshi4658 3 ปีที่แล้ว +2

      samjhaya toh hai kitna acche se.

  • @abhishekrajora8933
    @abhishekrajora8933 2 ปีที่แล้ว

    sir code which you written this is wrong because if end time same in that case we have to check the first time that's why

  • @punitmaheshwari6203
    @punitmaheshwari6203 3 ปีที่แล้ว

    Jonsi = jo bhi ....Hindi bhi shi ho jayegi isse toh

  • @jaislinbajwa3175
    @jaislinbajwa3175 2 ปีที่แล้ว +1

    This code isn't working and sorry to say but this is one of the rubbish course for c++ even basic concept bhi bhul jaoge

  • @btech_hub
    @btech_hub 3 ปีที่แล้ว +1

    🔥🔥🎉💥🔥

    • @vinaytamta7958
      @vinaytamta7958 3 ปีที่แล้ว +2

      0:01 Heard Ok Google? 😂😁

  • @prabhanjandesai1830
    @prabhanjandesai1830 3 ปีที่แล้ว

    V[I][1] kyun liya plzz help

    • @upasanapan8210
      @upasanapan8210 3 ปีที่แล้ว

      starting point ko check kara gya hai

  • @AnkitKumar-gr8xm
    @AnkitKumar-gr8xm 3 ปีที่แล้ว +2

    accha kamaai ka dhanda khola h waise long term investment...
    Aman be like - paisa hi paisa hoga by ads.

    • @yashverma3811
      @yashverma3811 3 ปีที่แล้ว +7

      ajib ho tum log bhi......agar unke paas paise nhi hoge to wo apne graphic artists, teachers ko paise kaha se dege.....tumhare liye itna bada course free me available kr diya wo tumhare liye importanat h ya fir wo paise kama rha h wo.......agar sirf ads dekh k tumhe itna bada course mil rha h so you should be thankful rather than complaining about ads.

  • @gogi-tech4183
    @gogi-tech4183 3 ปีที่แล้ว

    Sir I'm beginner which is best for me Android development or full stack web development? I have some basic knowledge html and css.
    Plz reply 🙏? I want work from as freelancer.

    • @sarthakrsharan174
      @sarthakrsharan174 3 ปีที่แล้ว +1

      Udacity for Android dev.

    • @rutvikrana512
      @rutvikrana512 3 ปีที่แล้ว

      Flutter or React for Android.
      If you want to do both web and app development. Go for React. If you only want to go for app development, Flutter is way better.

  • @rohitbhai7265
    @rohitbhai7265 3 ปีที่แล้ว

    🤘🤘🤘🤘🤘

  • @HustlingGeek
    @HustlingGeek 3 ปีที่แล้ว

    ✌️♥️🔥

  • @jassmanakfan555
    @jassmanakfan555 3 ปีที่แล้ว

    Second

  • @rishabhrajrishu_
    @rishabhrajrishu_ 3 ปีที่แล้ว

    Am I first?

    • @madhurmohnish
      @madhurmohnish 3 ปีที่แล้ว +7

      No u are rishab

    • @rishabhrajrishu_
      @rishabhrajrishu_ 3 ปีที่แล้ว

      @@madhurmohnish ye bdhiya tha guru

    • @garvtambi5786
      @garvtambi5786 3 ปีที่แล้ว

      @@rishabhrajrishu_ Padle...Mirzapur ke dialog me kuch nhi rakha!

    • @rishabhrajrishu_
      @rishabhrajrishu_ 3 ปีที่แล้ว

      @@garvtambi5786 padh le, gyan dene me kuch nhi rkha

  • @SurajKumar-vc4du
    @SurajKumar-vc4du 3 ปีที่แล้ว +6

    Thank you bhaiya ❤️