Minimum Platforms | Greedy Algorithms

Поділитися
Вставка
  • Опубліковано 9 лют 2025
  • Check our Website:
    In case you are thinking to buy courses, please check below:
    Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
    Code "takeuforward" for 15% off at GFG: practice.geeks...
    Code "takeuforward" for 20% off on sys-design: get.interviewr...?_aff=takeuforward
    Crypto, I use the Wazirx app: wazirx.com/inv...
    Take 750 rs free Amazon Stock from me: indmoney.oneli...
    Earn 100 rs by making a Grow Account for investing: app.groww.in/v...
    Linkedin/Instagram/Telegram: linktr.ee/take...
    ---------------------------------------------------------------------------------------------------------------------------------------------------- I have decided to make a free placement series comprising of video lectures(C++ and Java) on the entire SDE sheet.. ✅(bit.ly/takeUfo...)
    ✅Entire Series: bit.ly/placemen...
    ✅Problem link: practice.geeks...
    C++/Java Code: takeuforward.o...
    ✅Unacademy has launched a subscription that will help you learn and interact with your favorite teacher and will also help you clear your doubts! Check it out here: unacademy.com/.... (use coupon code TAKEUFORWARD to get 10% off)
    Join Unacademy's Pinnacle 2021; A Comprehensive and Concise Track to Become an Expert: unacademy.com/...
    Check out Unacademy’s Free Classes and tests here (For Desktops):
    www.codechef.c...
    unacademy.com/...
    unacademy.com/...
    ✅This is where I teach: ----- Use coupon-code "TAKEUFORWARD" for getting 10% on my course at GFG: bit.ly/striver_...
    ✅Use coupon-code "TAKEUFORWARD" for getting 10% for all GFG courses: bit.ly/tuf_gfgC...
    If you appreciate the channel's work, you can join the family: bit.ly/joinFamily
    Thumbnail Creator: / rikonakhuli
    ✅ Striver's Linkedin Profile: / rajarvp
    ✅ Instagram: / striver_79
    Connect with us: t.me/Competiti... (Use Link in Mobile only, if not works search "takeUforward" in telegram)..
    #dsa #leetcode #placements

КОМЕНТАРІ • 281

  • @amber.k
    @amber.k 4 роки тому +41

    Hi sir,
    Please help with the following doubt:
    If we sort the arrival and departure times. Is it necessary that arrival time and departure time will be at same locations for the same train. I mean if a train is leaving at 500 can we be sure it was for the same train which came at 50 can it also be for train coming at 200. Will this affect our platform occupation count.

    • @takeUforward
      @takeUforward  4 роки тому +75

      No it won't because it does not matters na which platform is getting vacant, but if someone leaves it is for sure that the train would have arrived that is why it is leaving, so one plat will go empty na!

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

      actually the idea is a train must leave before it's departure time (it means it must have arrival time

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

      We want to be able to know as soon as a platform becomes available. And that is only possible if the departure times are sorted in increasing order. If we keep the departure time unsorted i.e. mapped to the arrival times and only sort according to arrival times, when we iterate through the arrays, it is possible that the next trains departure time is earlier than that of current train, and our departure pointer is stuck at current train unnecessarily, when it could have been incremented if it was sorted and platform could have been empty. Hope this helps!

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

      sir as a train needs to arrive first to departure then.. shouldn't we just need to give the while condition as only i < n we need to check the dep array as terminating condition

  • @keerthi1070
    @keerthi1070 3 роки тому +252

    It is very difficult to convince my mind that we need to sort both arrays independently :)

    • @bharathkumar5870
      @bharathkumar5870 3 роки тому +10

      same..if ou got the intution,plz comment back

    • @shubhamkumbhare2725
      @shubhamkumbhare2725 3 роки тому +14

      its kind of hole in the solution. which is not getting filled.

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

      Yess samee

    • @jigarshah7434
      @jigarshah7434 2 роки тому +25

      The concept here employed is the train departing from station has to be the one which has arrived prior so it doesn't matter which train is leaving we are concerned only with the platform , if the platform is empty we can divert the new train there

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

      hey , its not that hard if you think it like a simulation problem, that means you are simulating the events which occur earlier to later events. In this way , you can clearly see the choices you have to make for a particular event as you are processing earlier events first. Hope it helps.

  • @takeUforward
    @takeUforward  4 роки тому +20

    Do comment on, should I add face in the video or not? Or shall I continue as I did previously?
    C++ Code: github.com/striver79/SDESheet/blob/main/NmeetingsCpp
    Java Code: github.com/striver79/SDESheet/blob/main/NmeetingsJava
    Instagram for live sessions: striver_79

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

      Please Make Full Maths Course Semesters Wise for Btech,BCA,Mtech and MCA Students

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

      Maths are so hard... Please cover all the maths topics also

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

      I prefer videos without face tbh

    • @Ji-yoon
      @Ji-yoon 4 роки тому

      I prefer videos without face

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

      I prefer without face. If you want to put it then please make bit smaller.

  • @akanshasingh6521
    @akanshasingh6521 4 роки тому +47

    Idk why people without even completing the video dislike it

    • @takeUforward
      @takeUforward  4 роки тому +62

      Happens, haters all round. But am glad they give a view :P

    • @chitranshsaxena59
      @chitranshsaxena59 3 роки тому +11

      I like without even completing the video .... >_

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

      It's just law.Even if you see the best video in youtube which may be like a hidden gem or popular there will be dislikes.Because people doesn't accept a video with no dislikes.They just do it for fun or yeah there may be haters.But i don't think these are haters just you people think i it is general trend of disliking like the one who started it just did it for fun as there is not dislike in this way a particular video got dislikes from people like him and some people see this video and sees the dislikes even if it is great come to some opinion and they will continue the trend.Most of the people are from this branch of trend continuation and some people do it for fun and some do it because of hate,dislike,not liking the way they do it and so on.I am just including something there may be some people who are selfish and they don't want everyone to see it so they dislike i think there is a possibility of this given the people i am around with.I don't say this for sure but yeah may be there is a chance these people are out there too.I am an expert of seeing weirdos. So yeah i think there is chance there are these kind of people

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

      @@watchlistsclips3196 Thankyou for this unwanted knowledge

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

      @@unbiasedcrook9157 Well she wants the reason and i am telling that may be this is unwanted knowledge to you but for her she wants to know and i am telling that.

  • @reassume4826
    @reassume4826 3 роки тому +30

    ming boggling method!!...i mean it's really difficult to come up with sorting two related arrays independently...we always try to rule out sorting independently..but here my goodness!!! you are amazing man!

  • @RISHURAJ-tm1sz
    @RISHURAJ-tm1sz 2 роки тому +7

    Tried my best to explain:
    Eg. 1st train: 6 to 12
    2nd train: 7 to 10
    1st train which will leave the platform will be at 10. It means any train arrive before 10 will need another
    platform (It is leaving means it has already arrived and standing on the platform). And the Arrival is also
    sorted that means next arrival will always greater than 6. So, any train which arrive surely after 6 and
    may before 10 will need separate platform. Here next arrival is 7, hence needed separate platform
    In simple words, any train whose arrival within 6 to 10 will need separate platform

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

    I found another Simple method by mistake
    1.Assume n trains take n platforms (Each train 1 platform ==> count++)
    2. Whenever new train comes just free the platforms which are preoccupied till that time (while loop to remove the prev trains)
    //After sorting the arrival and departure arrays
    for(int i=0; i

  • @shubhrajit2117
    @shubhrajit2117 8 місяців тому +1

    You actually dont need 2 different variables for result and plat_needed bcoz if one train leaves, another might come in its place later and we only care about the maximum platforms used:
    int plat_needed = 1, j = 0;
    for (int i = 1; i < n; i++) {
    if (arr[i]

  • @subhamjha8917
    @subhamjha8917 Рік тому +7

    We can sort it based on arrival time and then use min-heap to get the platform that will be empty at the earliest among the trains that are currently at different platforms. This is easy intuition. Overall complexity will remain same, but the approach explained here is definitely better and optimized. Great help!

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

    That "plz plz plz do subscribe the channel" a nice innocence on the face. I liked that ❤️ and solved the question on my own 😁🎉

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

    What a fabulous solution! Never had the intuition that both arrays can be sorted independently :)

  • @sudesh2911
    @sudesh2911 4 роки тому +91

    Keep the Face Bro...it feels as if we are discussing it face to face.

  • @humble.660
    @humble.660 2 роки тому +1

    Code in Python:
    class Solution:
    def minimumPlatform(self,n,arr,dep):
    arr.sort()
    dep.sort()
    res, count = 0, 0
    a, d = 0, 0
    while a < n:
    if arr[a]

  • @bitturanjan9539
    @bitturanjan9539 4 роки тому +24

    Add face as it become more interactive. Great explanation. Loved it ❤️

  • @shivshaktipandey9993
    @shivshaktipandey9993 2 роки тому +9

    i was also confused so here is my understanding
    1. if you are sorting both then
    allot platforms by arrival time and then while adding check if any train with departure time before arrival
    so if departure time is before it means you have already allotted platform for that
    bcz departure for a train always will be more than arrival so

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

    UNDERSTOOD........Thank You So Much for this wonderful video...........🙏🙏🙏🙏🙏🙏

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

    solved all my related problems and queries relating to this question in the vid!!! thankYou

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

    We can solve this question without sorting
    int findPlatform(int arr[], int dep[], int n)
    {
    vector platform(3000,0);
    for(int i=0; i

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

    Might be better than striver's code :) (Accepted on all platforms)
    T.C : O(2*NLOGN)+O(N)
    S.C : O(1)
    int findPlatform(int arr[], int dep[], int n)
    {
    sort(arr,arr+n);
    sort(dep,dep+n);
    int count=1;
    int i=1,j=0;
    while(i

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

      Nice One It took some time to understand it but worth it

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

    I am completely just in owe with your teaching style, you're doing an incredible job, the best channel so far to learn and strengthen the concepts, thanks a lot @takeUforward!!!

  • @prakharpathak9212
    @prakharpathak9212 4 роки тому +6

    The intuition was great 🔥... wonderful explanation.

  • @Shantisingh-tz5sr
    @Shantisingh-tz5sr Рік тому +1

    Wonderful Explanation!!!

  • @lostgen36
    @lostgen36 3 роки тому +6

    Damn..that is some intuition!

  • @HarshKumar-hn8ss
    @HarshKumar-hn8ss 9 місяців тому +1

    are you guys able to come with greedy solns optimal one on your own ?? like ive been doing coding from past 5 to 6 months now still these i am not able to come up on my own

  • @AmitSingh-xd4mj
    @AmitSingh-xd4mj 3 роки тому +1

    More elegant way of writing the same code
    int findPlatform(int arr[], int dep[], int n)
    {
    sort(arr, arr + n);
    sort(dep, dep + n);
    int totalPlatform = 1, maxPlatform = 0;
    int j = 0;
    for(int i=1; i

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

    UNDERSTOOD... !!!
    Thanks striver for the video... :)

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

    I have a doubt:
    You are saying that if a train is arriving at 120, but the first train leaving leaves at 500, so you are saying that how can a train arrive at 120 if the very first train which is leaving leaves at 500, so we need another platform for this train which has to arrive at 120.....right ?
    But,
    What if the train that is DEPARTING at 500, this train ARRIVED at 499 ?
    So, in this case, the train that arrived at 120, we could keep it in the same platform also because may be this train came at 120 and departed at 121........right ?
    Edit - Answer which i figured out is - if the "120" arrival train departs at "121", then the sorted departure array's first element will be 121.
    But i am still unable to get properly the intuition behind this.
    Someone plz explain

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

    Now i get this question. Your way of explaining is very very good.

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

      Thank you, do check out the other problems as well

  • @_var.onwheels
    @_var.onwheels 4 роки тому +11

    Can someone tell me the problem:
    1 - Sorted the pairs by departure time
    2 - Then add departure time in min heap priority queue
    3 - Check if arrival is greater than queue top, if it is smaller increase count

    • @takeUforward
      @takeUforward  4 роки тому +6

      Pairs cannot be together. Thats the problem. Just think yourself as a station master, and you just care how many came and how many went. Not when one came and when went

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

      It will not work...
      Lets take the example: arr[ ]: [100, 80, 70, 60] and dept[ ]: [700, 350, 90, 150]
      In this case, your algo will output 4 but the actual output is 3...
      I thought the same algo but performing dry run on some test cases help me understand what's the problem with this algo....i.e. using this we are not keeping track of arrival time of trains on a time frame....which is impacting our overall result.....As striver mentioned in the video we have to keep track of time or we are traversing the time and checking no. of platforms currently occupied....

    • @AmitSingh-xd4mj
      @AmitSingh-xd4mj 3 роки тому

      @@adarshsrivastava7765 Algo is giving correct result for your testcase.

    • @AmanKumar-zk6lu
      @AmanKumar-zk6lu 3 роки тому

      @@takeUforward thanks for station master example...helped me understand better.

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

      holy shitttt! I did the same in my first try (with some modifications) and it worked.
      I thought I'd be the only one trying this lmao

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

    MindBlowing and easy to understand intuition striverrrr!!!!!

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

    SHORTER CODE on same idea :
    Arrays.sort(arr);
    Arrays.sort(dep);
    int platform = 1, j = 0;
    for(int i = 1; i < n; i++){
    if(arr[i]

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

    Should I quit coding and search a different field altogether, I'm failing to crack these machine coding rounds, I'm failing every in Interview and it's been 3 years since I graduated, I lost considerable time learning technologies. Please advise me should I give it up ? I'm now 25 years old fresher

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

      You can prepare for SSC-CGL, it would take a maximum of six months to prepare for the exam but I would like to make it clear you can achieve anything if you study consistently with full dedication.

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

      Ask this question to yourself, then actual struggle starts...

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

    Extraordinary explaination bro it's really clear to understand by your explaination tq bro...

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

    Best content i have ever seen.....thank you so much ..and btw u slayed it

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

    Best explanation for the question. Thanks Striver.

  • @rahulkapoor2930
    @rahulkapoor2930 11 місяців тому +1

    Won't this be better?
    public class Solution {
    private static void fillArr(int s, int e, int[] arr) {
    for(int i=s;i

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

    Thanks a lot. You made me understand it.

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

    This question was asked me in Goldman Sachs interview

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

    all these greedy problems are like that only, follow up ques is meeting rooms 2

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

    your explaination is always very clear . thanks for your tutorials

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

    Bro for initializing platfrom_needed you should declare platform_needed=0 other wise while counting from first platform requirement the code calculate it as 2 instead of one

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

    can't we apply activity selection concept here make a vector pair and then sort it based on arrival time and then compare the starting and ending indexes accordingly

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

      I know we need to maintain a ds to store the dept time and that is gonna take a bit more space just wanted to confirm if this method will work or not

  • @abhishek-singh31
    @abhishek-singh31 4 роки тому +9

    Bhaiya I want to ask one question .
    I'm in 4th semester and is it okay if I don't get the best optimised approach and view editorial ?

    • @takeUforward
      @takeUforward  4 роки тому +7

      Yeah its okay

    • @abhishek-singh31
      @abhishek-singh31 4 роки тому +3

      @@takeUforward thank you bhaiya for all this contribution to the community 👍🏻

  • @hakunamatata-nl4js
    @hakunamatata-nl4js 8 місяців тому

    thank you so much. you explanations are way too good

  • @alt-f4gaming222
    @alt-f4gaming222 2 роки тому

    aree bhaiya , ek hi dil h kitne baar jeetoge....❤❤

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

    These greedy algorithms are simple and crazy 🤩😍. Loving them..

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

    amazing stuff !! subscribed

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

    cannot understand why after a platform is allocated to any train (when arr[i] >dep[j]), the 'i' pointer was not moved to point to the next element of arrival!

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

    Sir please help!
    Why does this not work
    Main thought : if a train's arrival time is smaller than or equal to least departure time of all trains then one more platform to use else not.
    Code:
    int findPlatform(int arr[], int dep[], int n) {
    int cnt = 0;
    set st;
    for (int i = 0; i < n; i++) {
    if (st.empty()) {
    st.insert(dep[i]);
    cnt++;
    } else {
    int leastDepartureTime = *st.begin();
    if (arr[i]

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

    This Question is a variation of "N meetings in one room" question, How ?
    Here, Instead finding out how many meetings we can arrange in one room we need to find out how many rooms are required if we want to arrange all given meetings.
    So, Posting a solution that is based on the solution that is given in "N meetings in one room" question video . Although it's not as efficient as the one given in this video but you can take a look if you wish.
    SOLUTION :
    class Train {
    public int arr, dep;
    public Train(int arr, int dep){
    this.arr = arr;
    this.dep = dep;
    }
    }
    class TrainComparator implements Comparator{
    @Override
    public int compare(Train t1, Train t2){
    // Sorting in Ascending order of arrival time
    if(t2.arr minHeap.peek())
    minHeap.poll();
    minHeap.add(trains.get(i).dep);
    platform = Math.max(minHeap.size(), platform);
    }
    return platform;
    }
    }

  • @huzaif.2004
    @huzaif.2004 Рік тому

    where can i find the doc which is shown in 0:09?

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

    Am i the only one who is not able to understand the intuition of why this approach works or is there anyonr else with me😭

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

    Thanks bro for helping this high school kid out. :)

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

    If i am sorting the two arrays then arrival and departure time for a train gets jumbled. I am confused why we are doing this?

    • @takeUforward
      @takeUforward  4 роки тому +4

      Since arrival < departure always, we just counting how many trains enter and leave throughput the day.

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

      @@takeUforward Why not do the same for Activity Selection Problem ?

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

    can we do it this way:
    1) make an array of pairs of starting and departure time of all trains; and sort it(for example, python does this kind of sorting by considering 0th index of pair first, and then 1th index)
    2) initialize platforms to be 1, and add departure time of first train in a priority queue.
    3) then on next train:
    i)if arrival of it is greater than top element in the priorityQueue, remove the top element and add departure time of this train in the priority queue.
    ii) if arrival is smaller than top element of the priorityQueue, then increase platforms by 1 and add departure time of this train in the priorityQueue.
    repeat step 3 till we reach the end of array

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

      Yes nikhil but we need a extra space for it
      I implemented the above code
      int findPlatform(int arr[], int dep[], int n)
      {
      int i,count;
      priority_queuepq;

      vectorv;

      for(i=0;i

    • @atulwadhwa192
      @atulwadhwa192 9 місяців тому

      Thanks for the intuition. Here's my code for the same
      int findPlatform(int start[], int end[], int n)
      {
      // Your code here
      vector v;
      for(int i=0;i

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

    Your explaination is best very crystal clear thankyouu

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

    are but.. when we sort both the arrays ..their indexes are not matching for example.for arrival time 50 departure was 550 but after sorting it became 500????? how does this makes sense?

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

      You need how many are in at a time..
      So when they are entering that matters, because we know for sure departure will always be after entering.
      Hence it makes sense..

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

      @@takeUforward thanks

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

    Solution using min priority queue
    int findPlatform(int arr[], int dep[], int n)
    {
    int i,count;
    priority_queuepq;

    vectorv;

    for(i=0;i

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

    bhaiya..ap bht acha parhate hai..hum avi backtracking kr rehe..apka sde sheet se..pls jaldi jaldi vdo laya..

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

    Thank you, Striver!!!!!

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

    Can I do this ------ i tried with different test cases and got the right answer but WA on gfg.
    Please tell me where I made the mistake.
    1) put in a multimap, so that both set of values are sorted according to dep_time.
    2) have a queue. Insert -1 into it.
    3) iterate through the multimap such that
    if i->arr_time > q.front() then
    {
    // this means no need for new platform
    q.pop() // old train gone
    q.push(i->dep_time) // new train came
    }
    else {
    // this means new platform is required
    p++;
    //no need to pop as no train to leaving. just put new train
    q.push(i->dep_time)
    }
    4) return p;

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

    Thanks bro
    Loving your videos 😍

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

    bro, I have a doubt. if we are sorting both arrays separately then after sorting it might be possible that at some index the arrival and departure time does not belong to the same train. So suppose in your example, if the train which is leaving at 500 does not even arrive at 50 and came at 120 or so, then how is this solution working in it.. that part is really confusing. Shouldn't we use a custom class "train" and sort it using our own comparator according to arrival and so.

    • @takeUforward
      @takeUforward  4 роки тому +4

      No bro, even if they are not same, it does not matters to me, because i know always arrival of a train is before departure. So i am sure if a train is areiving it will first arrive and then which ever train departs it has for sure arrived and hence is departing, this is the logic here.

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

      @@takeUforward I had the same doubt. Tnx for the clarification

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

    Hello, Im asked to optimize this code. Can someone help? I'm getting this message in terminal "Your program took more time than expected.Expected Time Limit : 1.38sec
    Hint : Please optimize your code and submit again."

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

    Your explanation is lit... and very easy for understanding

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

    I know everyone is confused but still is there anyone who understood, and can explain me why are even sorting arr[i] and dep[j] both independently??

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

    God level explanation..
    Thank you very much!

  • @subhrajitdas247
    @subhrajitdas247 4 роки тому +28

    Bhaiya face add hii rakhiye

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

    Great video and visualization!

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

    Very beautifully explained!!!

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

    but can we solve it using binary search, its tagged under binary search in gfg

  • @DeepakSharma-ue3pn
    @DeepakSharma-ue3pn 3 роки тому

    imagine only second platform being occupied

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

    achaai ki bhi seema hoti hai sir ! thank you..😁

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

    Great explanation!!

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

    You can add this solution Link to the SDE sheet page too. Currently, the link to this solution is not there in SDE sheet.

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

    16:22 c++ solution

  • @prashantsingh-4233
    @prashantsingh-4233 4 роки тому +1

    Thanks bhaia very well explained ❤️
    Can you pleasee upload the problem link of all remaining questions.

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

    Superb explanation bro. Thank you!!!

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

    Amazing, Thank you!

  • @English_Vinglish-c9o
    @English_Vinglish-c9o Рік тому

    we want maximum or minimum platforms?

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

    Awesome as always!

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

    i am so dumbbbb

  • @yashmundada2483
    @yashmundada2483 7 місяців тому

    why is this incorrect. making use of a heap to keep track of the smallest meeting time
    class Solution:
    def minimumPlatform(self,n,arr,dep):
    comb = list(zip(arr, dep))
    departureTimes = []
    for arrival, departure in comb:
    if departureTimes and arrival>departureTimes[0]:
    heapq.heappop(departureTimes)
    heapq.heappush(departureTimes, departure)
    return len(departureTimes)

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

    My O(N) - Time and Space Complexity Solution - Line Sweep Method:
    int findPlatform(int a[], int b[], int n)
    {
    // Your code here
    int count[2400]={0};
    for(int i=0;i

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

    Thank you so muchc Raj Bhai.

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

    Greta explaination!

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

    1:39 minimum**

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

    understood the aprroach bhayiya but how can we come up with this kind of approach apne aap se like sorting them individually did not even cross my mind while trying

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

    still didn't understand the intution behind this

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

    correction in words it is not maximum number of platform we need to find minimum number of platform.

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

    Understood 💯💯💯

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

    Is anyone knowing the intuition behind this>

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

      He explained the intuition...platforms are vacated when trains leave

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

    God level explanation!!

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

      Please explain the intuition

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

      @@jiosim1377 bro intuition is: no matter which train is leaving or which is arriving because if at initial moment any train arrives then we need a platform or if a train departure then the platform will empty. So that's why we are sorting the arrival and departuring time.
      Example-
      0900 0910 1100
      0920 0945 1130
      So here as you can see I have sorted both the times so now--
      first train will leave at 09:20 and next train is coming at 09:10 (before the first train goes) so we need one more platform.
      But if after leaving of one train next will arrive that means first platform will get empty.

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

      @@jiosim1377 go through the video once, you will understand more clearly. ❤️

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

    bro please provide the links of all problems in the sde sheet . We are not able to find all the problems on leet code and adding links makes our work easier . Thanks in advance :)

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

      Its either at gfg or leetcode, just google the problem names!!

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

      @@takeUforward thanks...how do i contact you if i have any doubts ?

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

      @@nishanthmolleti188 Instagram or put the comment, I usually reply to a comment where someone is asking something

  • @nivedhitha704
    @nivedhitha704 8 місяців тому

    i tried a different approach...this also works........
    // You are using Java
    import java.util.*;
    class Activity{
    int start,end;
    Activity(int start,int end){
    this.end=end;
    this.start=start;
    }
    }
    class MyComparator implements Comparator{
    public int compare(Activity a1,Activity a2){
    return a1.end-a2.end;
    }
    }
    class Main{
    public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int count = 0;
    int start[] = new int [n];
    int end[] = new int [n];

    List obj = new ArrayList();
    List temp = new ArrayList();
    for(int i=0;i

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

    Very well explaination!

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

    awesome explaination it helps lot of students

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

    Can someone explain why sorting the two arrays didn't affect the answer?

    • @takeUforward
      @takeUforward  4 роки тому +4

      Because we only care as a station. Kb aa rahe and kab jaa rhe matter krta. Ovio h ki jaane wla time hmsha aane wle k bd hi aaega

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

      @@takeUforward Okay bhaiya, aa gya smjh, Thanks!
      And you are doing a wonderful job I love your channel!

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

    Amazing explanation!

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

    can't we use kadane's in this?