Car Pooling | Leetcode

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • This video explains a very important simulation based programming interview problem which is the car pooling problem from leetcode 1094. In this video, I have first explained the problem statement using simple examples and then explained the observation and intuition. Finally, I have given the dry run of the idea along with code implementation.
    CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    ======================================PLEASE DONATE=============================
    🧡 SUPPORT OUR WORK: / techdose
    💚 UPI-ID: surya.kahar@ybl
    💞JOIN Membership: / @techdose4u
    ==============================================================================
    INSTAGRAM : / surya.pratap.k
    LinkedIn: / surya-pratap-kahar-47b...
    WEBSITE: techdose.co.in/
    TELEGRAM Channel LINK: t.me/codewithTECHDOSE
    =======================================================================
    USEFUL LINKS:
    🟠Must do TIPS to ACE Virtual Interview: • 🔴Must do Tips to ACE y...
    🟢Best strategy to excel your coding interview: • 🔴Best strategy to exce...
    🟡Get your dream job in 1 month: • 🔴Get your dream job in...
    🔵How to crack dream job in just 2 months: • How to crack dream job...
    🟣7 Days DSA plan: techdose.co.in/7-days-dsa-che...
    RELATED LINKS:
    CODE LINK: gist.github.com/SuryaPratapK/...

Komentáře • 25

  • @LeagueOfChallenger
    @LeagueOfChallenger Před 2 lety +4

    Congrats on reaching 100k subscribers!

  • @pranavsharma7479
    @pranavsharma7479 Před 2 lety +1

    You back wow

  • @TomJerryFilm
    @TomJerryFilm Před 2 lety +1

    Tech Dose provides the best videos for computer science👍🏾👍🏾👍🏾, may I know what software and pen tablet you use for the videos?

  • @arvindrawat3641
    @arvindrawat3641 Před 2 lety +1

    did this ques 3 days ago. great explanation

  • @techworld3043
    @techworld3043 Před 2 lety

    Love the video bro, thanks . what software are you using to type ?

  • @Mukesh-nx8tf
    @Mukesh-nx8tf Před 2 lety

    what app do you use to record screen and for white board?

  • @mk-mc8yx
    @mk-mc8yx Před 2 lety

    Thankyou. Before I saw your solution, I came up with my approach. But your approach looks simple. Can you have a look at my soln, appreciate any feedback. What I am a basically doing is construct two sets of nodes which are startJourney and endJourney nodes. And an array of all bus stops. Iterate through all bus stops and at each bus stop process any start/end Journey nodes.
    Only downside with my approach is I guess it is quadratic time complexity ? I know thats bad, but just wanted to share my first attempt approach.

    • @mk-mc8yx
      @mk-mc8yx Před 2 lety

      Here is it: feedback appreciated.
      //insert relevant headers
      using namespace std;
      typedef struct Trip {
      int numPassengers;
      int pickLoc;
      int dropLoc;
      } Trip ;
      int processStartNodes(int loc, const unordered_multimap &sNode, int capacity) {
      auto range = sNode.equal_range(loc);
      for_each (range.first, range.second,
      [&capacity](const unordered_multimap::value_type &x){
      cout

  • @patigesuhas
    @patigesuhas Před 2 lety

    Wouldn't it easier if we just used hashmap, and entering indices are added and leaving indices are substracted?

  • @shubhamhembram9144
    @shubhamhembram9144 Před rokem

    Sir, can you explain the marathon race problem where the runner has to pick required number of water bottles to survive and complete the race. He also has some water bottles initially but are not enought to complete the race. so he has to stop mininum to times to complete the race?

  • @sayantaniguha8519
    @sayantaniguha8519 Před 2 lety +2

    Aj Q ni aya telegram mein
    So, should we consider this a part of 28-Days Arrays ?

    • @techdose4u
      @techdose4u  Před 2 lety +1

      Person in charge is sick :)
      Will resume once he recovers :)

  • @mayukhchatterjee4863
    @mayukhchatterjee4863 Před 2 lety +1

    Hello Tech Dose...I have a question how did you get Mtech in Jadavpur University? Was it through Gate score? Can you please explain me the application procedure.

  • @coder1015
    @coder1015 Před 2 lety

    cost for joining the dsa course ??

  • @nivash8024
    @nivash8024 Před 2 lety +1

    Explain leetcode 996 sir

  • @priyankabahety895
    @priyankabahety895 Před 2 lety

    Can you please provide java code for this approach.

  • @rajankhunt7002
    @rajankhunt7002 Před 2 lety

    Optimum location of point to minimize total distance [OR] Rasta and Kheshtak in SEARCH AND SORT if you make on video plz, plz, plz,

  • @supratimbhattacharjee5324

    //It can also be done using hashing
    class Solution {
    public:
    bool carPooling(vector& trips, int capacity) {
    map netPas;
    for(auto x: trips)
    {
    netPas[x[1]]+=x[0];
    netPas[x[2]]-=x[0];
    }
    for(auto x: netPas)
    {
    capacity-=x.second;
    if(capacity

  • @ravindrakawale1014
    @ravindrakawale1014 Před 2 lety

    This is my solution of O(n) complexity -
    class Program
    {
    static void Main(string[] args)
    {
    int[,] trip = new int[,] { { 3, 0, 7 }, { 1, 4, 7 }, { 4, 7, 10 } };

    int carVacantSit = GetCarVacancy(trip);
    if(carVacantSit > 0)
    Console.WriteLine("Car Vacent seats - " + carVacantSit);
    else
    Console.WriteLine("Car is full");
    }
    public static int GetCarVacancy(int[,] trip)
    {
    int carCapacity = 5;
    int carCurrentPassenger = 0;
    int drop = 0;
    Dictionary dropingPassenger = new Dictionary();
    for(int i=0; i < trip.Length / 3; i++)
    {
    drop = trip[i, 1];
    if(dropingPassenger.Count == 0)
    {
    dropingPassenger.Add(trip[i, 2], trip[i, 0]);
    carCurrentPassenger += trip[i,0];
    }
    else
    {
    if (dropingPassenger.ContainsKey(drop))
    {
    carCurrentPassenger -= dropingPassenger[drop];
    }
    if(dropingPassenger.ContainsKey(trip[i, 2]))
    {
    dropingPassenger[trip[i, 2]] += trip[i, 0];
    carCurrentPassenger += trip[i, 0];
    }
    else
    {
    dropingPassenger.Add(trip[i, 2], trip[i, 0]);
    carCurrentPassenger += trip[i, 0];
    }
    }
    }
    return carCapacity - carCurrentPassenger;
    }
    }

  • @sarthaksarthak6912
    @sarthaksarthak6912 Před rokem +1

    O(n)
    class Solution {
    public:
    bool carPooling(vector& trips, int capacity) {
    int start[1001]={0};
    for(int i=0;i