L10. Minimum number of platforms required in a railway station

Sdílet
Vložit
  • čas přidán 25. 05. 2024
  • Find problem link, notes under Step 12: takeuforward.org/strivers-a2z...
    Follow me on socials: linktr.ee/takeUforward

Komentáře • 48

  • @jritzeku
    @jritzeku Před měsícem +8

    Visualization/Intution that helped undertand why we sorted the departure data:
    - Firstly, notice that the time pairs(arrive,depart) is NOT same as depart,arrive like in airplane.
    ->when train arrives, its jus sitting at station doing nothing! With that said, we do not have to view
    arrive , depart as one unit of data tied together.
    -So the person responsible for clearing assigning tracks is basically just looking at his clock the whole time!!
    ->After every few minutes, he is going to do one of 3 things:
    -do nothing (neither arrival not departure happened) //no need to code this
    -clear a track (becuase it departed)
    ->to do this, it would be convenient for the depart times to be in sorted order.
    -open new track (because new train arrived before an old train departed)
    ->to do this, it would be convenient for arrival times to be in sorted order
    -NOTE: arrival times are by default given in sorted order so idk why we had to sort it.

    • @ADG-ob4xi
      @ADG-ob4xi Před 15 dny

      nice explanation man, really helpful

  • @akashvines0509
    @akashvines0509 Před 2 měsíci +18

    Waiting for Heaps and strings playlist 🙌👍

    • @nitpBlogs
      @nitpBlogs Před 12 dny

      See Aditya Verma playlist

  • @SAKETGOYAL-yf7ol
    @SAKETGOYAL-yf7ol Před měsícem +20

    Hi, the initial approach seems incorrect , consider timings as {(10,12),(11,16),(13,14),(15,17)} , here 2 platforms work but the brute force code gives 3 as answer

    • @harshalrelan3113
      @harshalrelan3113 Před měsícem +1

      exactly the same doubt thanks for pointing it out

    • @akshaykolluru962
      @akshaykolluru962 Před měsícem +2

      I think the brute force solution is wrong here
      for Ex:(1000,1030),(1010,1015),(1020,1030)
      Here max intersections are 3
      but ans is 2

    • @aartibhatnagar3989
      @aartibhatnagar3989 Před měsícem +2

      great observation skills

    • @travelsphere1414
      @travelsphere1414 Před měsícem

      Exactly what Im thinking about!!

    • @twinklelight9829
      @twinklelight9829 Před 6 dny

      can u please explain why this approach failed..? what went wrong in the thought process?

  • @SukritAkhauri
    @SukritAkhauri Před měsícem +3

    This is one of the finest solution, i have seen striver. It is really waoo.
    Good job, keep sharing the learning with us.

  • @worldfromhome4033
    @worldfromhome4033 Před 22 dny

    This explanation is so much better and intuitive than the previous video!! Thanks Striver

  • @Akash-Bisariya
    @Akash-Bisariya Před měsícem +2

    You made this question looks so easy. Wow!!

  • @kevalkrishna4134
    @kevalkrishna4134 Před 28 dny

    Ur explanation has become good as compared to ur previous video on the same question ,a lot better

  • @venumsingh
    @venumsingh Před měsícem +3

    This is cleverly crafted problem of meeting rooms.

    • @ababhimanyu806
      @ababhimanyu806 Před měsícem +2

      why we cant use that approach in this question?

    • @jotsinghbindra8317
      @jotsinghbindra8317 Před měsícem +4

      @@ababhimanyu806 udhr ek room me hi meetings krni thi toh T/F hi bs judge krna tha hr meeting pe and count dena tha , yaha multiple rooms le skte ho toh multiple rooms ki entry and exit ko dekhna prega ,usko manage kaise kroge?(you cant make a seperate vector for it nhi toh fir baar baar iterate krna prega usko extra TC aayega)

  • @kondalaumamaheshwararao2697
    @kondalaumamaheshwararao2697 Před měsícem +1

    yes, waiting for Heaps and strings playlist

  • @Dsa_kabaap
    @Dsa_kabaap Před 2 měsíci +6

    Sir please start making videos on strings and stacks

  • @huungryyyy
    @huungryyyy Před 27 dny

    Like I was thinking that why are you making the same video again but when i saw both the videos i got shocked by the improvement in your teaching skills bhaiyaa i didnt get this question in the previous solution but when i saw this explanation i got all my concepts cleared. Thanku so much striver for this brilliant explanationn.😊😊🙂🙂

  • @SAICHARAN0321
    @SAICHARAN0321 Před měsícem +5

    Waiting for string and stack queue videos more

  • @iscommendable13
    @iscommendable13 Před měsícem +1

    eagerly waiting for heap and string playlist

  • @shashwatkumar6965
    @shashwatkumar6965 Před měsícem +1

    We can also solve it in O(N) TC and O(1) Space:
    Since the time is in 24hr format, we can keep a time array of size 2360 (max time = 23:59)
    Then for evey minute count the number of trains present
    Finally loop through the time array and take the max count
    Eg: arr[] = {1000, 1030, 0900},
    dep[] = {1100, 1130, 0945}
    So, in time array from 0900 till 0945 count will be 1, then from 1000 till 1030 count will be 1, but from 1030 till 1100 count will be 2 and from 1100 till 1130 count is 1. So max count is 2 which is the answer. So in this case we dont need to sort the array, we can just keep the count of trains at every minute.
    Code:
    vector time(2360, 0);
    for(int i = 0; i < n; i++){
    for(int j = arr[i]; j

    • @drishtiambastha3141
      @drishtiambastha3141 Před měsícem

      but nested for loop causes O(N^2)

    • @shashwatkumar6965
      @shashwatkumar6965 Před měsícem

      @@drishtiambastha3141 The nested for loop can run upto max 2360 times for every ith element which makes TC = O(N * 2360) ~= O(N)

    • @thoughtsofkrishna8963
      @thoughtsofkrishna8963 Před 26 dny

      But log(n) value is lesser than the 2360,

    • @shashwatkumar6965
      @shashwatkumar6965 Před 26 dny

      @@thoughtsofkrishna8963 no its not. O(2360) ~= O(1) and O(log n) > O(1)

    • @dabhijay4997
      @dabhijay4997 Před 22 dny

      ​​@@shashwatkumar6965​
      it's not always like O(constant)= O(1). well theoretically it is true but practically not for example if in constraints it is given that 1

  • @JayakanthS
    @JayakanthS Před měsícem

    Pls continue this

  • @kshitijjha6737
    @kshitijjha6737 Před 2 měsíci

    Understood

  • @shashankvashishtha4454

    understood

  • @krishnavamsireddyduggiredd8539

    why sliding window after sorting is giving wrong answer for this question?

  • @kunalkumar1964
    @kunalkumar1964 Před 2 měsíci

    Hi bhaiya, how are you!

  • @namrathabejgam
    @namrathabejgam Před 12 dny

    Another (unpopular?) approach: We can solve it like how we solve "Array Manipulation" from hackerrank (leetcode discuss thread available on the same with title "Minimum number of platforms required for a railway", unable to link it here probably because of restriction)

  • @dababy2882
    @dababy2882 Před měsícem +1

    Why did we sort departure time independently? Wouldn’t it change the question? After sorting the departure time of train will change and the whole question will be changed. Someone please answer

    • @smarajitadak6681
      @smarajitadak6681 Před měsícem +2

      The main concept lies in finding the timings when the platform will be free and busy. After sorting the timings we can easily see the time when a new train will arrive and when the departure of an existing train in an platform will take place. If the arrival time is lesser than the departure time it means that there is still a train in the platform by the time when the new train arrives irrespective of which trains these are in the original array. So in this case we will increase the number of platforms since we will require one more to station the arriving train. And in the else condition we will decrease the numbers of alloted platforms since the departing time is lesser than the arriving time .

    • @jritzeku
      @jritzeku Před měsícem

      I too had this question. There is more dicussion in the older version of this problem that Striver uploaded few years ago.

    • @tummalapallikarthikeya2412
      @tummalapallikarthikeya2412 Před 27 dny +1

      @@smarajitadak6681 very nice explanation bro, tysm

    • @devmadaan5146
      @devmadaan5146 Před 8 dny

      Asaan bhasha Mai,
      We sorted acc to time,
      The clock is ticking!! We find the train which arrived, if arrived then platform++ , if depart then platform --,

  • @ITSuyashTiwari
    @ITSuyashTiwari Před 7 dny

    solved using min priority queue anyone else

  • @storm19019
    @storm19019 Před měsícem

    Livestreaming platform

  • @piyushkala9707
    @piyushkala9707 Před 17 dny +1

    solution he gave for naive approach and code for naive in tuf is wrong i think
    3
    0900 0920 1010
    1200 1000 1150
    just run that code with give input and check output on gfg
    int ans=1; //final value
    for(int i=0;i

  • @ayobrrr
    @ayobrrr Před 8 dny

    class Solution:
    def minimumPlatform(self,n,arr,dep):
    # code here
    plat=[]
    mixarr=[[int(arr[i]),int(dep[i])] for i in range(len(arr))]
    mixarr=sorted(mixarr,key=lambda x:x[1])
    for a,d in mixarr:
    assignedtosomeplat=False
    for i in range(len(plat)):
    if plat[i]

  • @yasharthsingh3263
    @yasharthsingh3263 Před 2 měsíci +2

    First comment 😀