Minimum Number of Moves to Seat Everyone | Counting Sort | Sort | Leetcode 2037 | codestorywithMIK

Поделиться
HTML-код
  • Опубликовано: 22 авг 2024
  • Whatsapp Community Link : www.whatsapp.c...
    This is the 43rd Video of our Playlist "Leetcode Easy : Popular Interview Problems" by codestorywithMIK
    In this video we will try to solve a good practice Array problem : Minimum Number of Moves to Seat Everyone | Counting Sort | Normal Sort | Leetcode 2037 | codestorywithMIK
    I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Also, please note that my Github solution link below contains both C++ as well as JAVA code.
    Problem Name : Minimum Number of Moves to Seat Everyone | Counting Sort | Normal Sort | Leetcode 2037 | codestorywithMIK
    Company Tags : will update soon
    My solutions on Github(C++ & JAVA) : github.com/MAZ...
    Leetcode Link : leetcode.com/p...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My Recursion Concepts Playlist : • Introduction | Recursi...
    My GitHub Repo for interview preparation : github.com/MAZ...
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    Summary :
    Approach 1: Frequency Counting
    This approach uses frequency arrays to keep track of the number of students and seats at each position. Here is a summary:
    Initialization: Create two vectors position_seat and position_stud of size 101 (to cover seat positions from 0 to 100) initialized to 0.
    Frequency Counting: Iterate over the seats and students arrays to populate position_seat and position_stud respectively.
    Matching Positions: Use two pointers i and j to traverse the frequency arrays. For each non-zero entry in position_seat and position_stud, compute the moves as the absolute difference between the indices and decrement the counts. Continue this until all students are seated.
    Result: The total moves are accumulated in the variable result.
    Time Complexity: O(n + max_position)
    Space Complexity: O(max_position)
    Approach 2: Sorting
    This approach involves sorting both the seats and students arrays and then directly pairing them based on their sorted order. Here is a summary:
    Sorting: Sort both the seats and students arrays.
    Computing Moves: Iterate through the sorted arrays and calculate the absolute difference between corresponding elements to get the total number of moves.
    Result: The total moves are accumulated in the variable moves.
    Time Complexity: O(n log n) due to the sorting step
    Space Complexity: O(1) as it uses a constant amount of extra space
    ✨ Timelines✨
    00:00 - Introduction
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024

Комментарии • 11

  • @ashutoshbiswal7
    @ashutoshbiswal7 2 месяца назад +3

    I really like your consistency in putting up videos ❤

  • @tutuimam3381
    @tutuimam3381 2 месяца назад +2

    Thanks a lot 👍

  • @gui-codes
    @gui-codes 2 месяца назад

    Thanks a lot for counting sort. I couldn't understand from leetcode official solution.

  • @gauravbanerjee2898
    @gauravbanerjee2898 2 месяца назад +1

    Thanks a lot bhaiya ❤❤

  • @floatingpoint7629
    @floatingpoint7629 2 месяца назад

    please also solve LC-3181 (max total reward ii), its part i is in your repo but part ii is missing. thanks!

  • @simandhar1701
    @simandhar1701 2 месяца назад +1

    Hello , Can you please start a playlist on Trie Core and Concepts just like you have your Dp and Graph playlist?

    • @codestorywithMIK
      @codestorywithMIK  2 месяца назад +2

      Can you try this - ruclips.net/p/PLpIkg8OmuX-I99uuP2BZOz4mI_lms4gVG&si=d2Xc7cJ4uodW7dqN
      It has only 5 videos but it will remove the fear of TRIE

  • @pokeindia5361
    @pokeindia5361 2 месяца назад

    Bhaiya please *Longest valid parantheses* question pe video banaiye please.... Bhaiya banaoge ya nhi ye bhi toh batado

  • @ReshuSharma-jc7yu
    @ReshuSharma-jc7yu 2 месяца назад

    Bhaiya aapki backtracking ki series kab tak aajayegi

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 2 месяца назад +2

    public int minMovesToSeat(int[]seats,int[]students){
    int[]studentFreq =new int[101];
    int[]seatLoc=new int[101];
    for(int loc:seats)
    seatLoc[loc]++;
    for(int student:students)
    studentFreq[student]++;
    int ans=0,j=0;
    for(int i=0;i

  • @dhairyachauhan6622
    @dhairyachauhan6622 2 месяца назад +1

    Hello bhaiya, knight ban jata agar Saturday ka contest cancel nhi hota 😢. Feeling really sad about it. Nevertheless will try this Sunday. 😃