Minimum Number of Moves to Seat Everyone - Leetcode 2037 - Python

Поділитися
Вставка
  • Опубліковано 11 жов 2024

КОМЕНТАРІ • 46

  • @yelgabs
    @yelgabs 4 місяці тому +40

    The way this question was worded made it hard to understand.

    • @asagiai4965
      @asagiai4965 4 місяці тому +3

      This.
      It is an easy question, some people would think hard or be confused about.
      This is the problem with programmers or engineers sometimes making something easy confusingly hard.

    • @RTZemun
      @RTZemun 4 місяці тому +2

      sounds like a skill issue to me

    • @whyredvince
      @whyredvince 4 місяці тому +9

      @@RTZemun Yeah on part of the person who wrote this question

    • @GPT-X938
      @GPT-X938 4 місяці тому +2

      @@RTZemun shoo fly

    • @RTZemun
      @RTZemun 4 місяці тому

      @@GPT-X938 zap zap can win

  • @Garensonic
    @Garensonic 2 дні тому

    Counting sort has O (m + n) time and O (m + n) space where n is the # of seats and m is the number of students. Sorting is essentially in O(nlogn) + O(mlogm) time since both arrays were being sorted. But there was a constraint in this problem that n is up to 100 and m + n does not exceed 300

  • @adama7752
    @adama7752 4 місяці тому +8

    Man finds counting sort hammer. Processed to see counting sort nails.

  • @jessicakoch2331
    @jessicakoch2331 4 місяці тому +1

    i literally had no idea what they were asking in this question….once nice thing in interviews is that at least you can ask clarifying questions

  • @freecourseplatformenglish2829
    @freecourseplatformenglish2829 4 місяці тому

    considering array is small sorting is sweet and simple approach. Counting sort can be discussed if interviewer ask for more optimised approach.

  • @sandro-of9fq
    @sandro-of9fq 4 місяці тому +1

    You are doing god's work. I can't describe to you how much your videos have helped me in learning algorithms. I will forever be grateful!

  • @chisomedoka5651
    @chisomedoka5651 Місяць тому

    after seeing your diagram, I was able to come up with the solution, moving forward I'll try and see if I can draw the problem out

  • @junaidmahmud2894
    @junaidmahmud2894 4 місяці тому +3

    If you consider space complexity, nlogn solution would be preferable

    • @sophiophile
      @sophiophile 4 місяці тому

      Space complexity of python's built in sort (timsort variant) is theta n. So all the solutions are basically equivalent for time/space.

    • @sophiophile
      @sophiophile 4 місяці тому

      Space is not free for sort in python. It's omega(nlogn).

    • @junaidmahmud2894
      @junaidmahmud2894 4 місяці тому

      Exactly. Based on that, if I consider the algorithm takes less space and less time, I would go for sorting.
      It will work well even after removing the constraints.

  • @AnordinaryMan007
    @AnordinaryMan007 4 місяці тому +2

    Thanks for the different approaches.

  • @kavyanshpandey3823
    @kavyanshpandey3823 3 місяці тому

    1. Sort both array.
    2. Add abs different of same index value.

  • @Pegasus02Kr
    @Pegasus02Kr 4 місяці тому

    honestly can't say trying counting sort is meaningful in this problem.
    but it was a great example to show big-O is not always correct measure

  • @pastori2672
    @pastori2672 4 місяці тому

    yeah i came up with both solutions and was confused why the regular sorting was consistently faster then couting sort

  • @asagiai4965
    @asagiai4965 4 місяці тому +2

    This is an example of how to make an easy question confusing.
    Neet's explanation is good.
    But how is this question presented? It makes it confusing.
    Also, about the constraints. How I look at it is; students and seats are less than or equal 100 but not less than 1.
    Does that mean the. Max # you can iterate is 100? The number of items in each array doesn't matter?
    But both must not be greater than 100 or less than 1.
    Example if seats [1~100] and students [1~100] then the moves will be 0? Because every students have every seat?

  • @E1an9640
    @E1an9640 4 місяці тому

    Big Fan of your work here but I have one suggestion if you could give a formal proof for how the solutions works for questions like these it wud be excellent I dont think most people dont cover it nonetheless it is quite important too.

  • @karanmehta2890
    @karanmehta2890 4 місяці тому

    When the n is small, nlogn and n tend to be the quite the same. That is why sorting is better in this case.

  • @kavyanshpandey3823
    @kavyanshpandey3823 3 місяці тому

    Following you since last 4 month with 95 percent consistency

  • @shraveenb.s3983
    @shraveenb.s3983 2 місяці тому

    if logn is of base 10 then any n below 10 or below 100 would have a significantly lower value than n + 100. After 100 nlogn will start doubling. So for O(n + 300) < (300 log 300)

  • @jotrades26
    @jotrades26 4 місяці тому

    This week , Leetcode has made us to count numbers 👏👏

  • @John-ht4xv
    @John-ht4xv 4 місяці тому

    thanks man i've been doing the daily Q for the last few weeks and it's always good to double check against your solutions

  • @hemanthhvv4296
    @hemanthhvv4296 4 місяці тому

    I really liked the way, you explained about the need of those sort methods A.K.A Rant 😂

  • @JamesBond-mq7pd
    @JamesBond-mq7pd 4 місяці тому

    My solution
    seats = sorted(seats)
    students = sorted(students)
    res = 0
    for i in range(len(students)):
    res += abs(seats[i] - students[i])
    return res

  • @kraav4ikk6
    @kraav4ikk6 4 місяці тому

    thank you for different solutions!

  • @jparmar1
    @jparmar1 4 місяці тому

    This question was so weirdly worded.
    Meanwhile a trivial solution is to find the difference between the sums of the arrays. It did solve 53 testcases for me 😅😂😂😂😂

  • @vickyorg
    @vickyorg 4 місяці тому

    Sort both array
    SUM += diff from i to n indices did the trick
    AM I WRONG FROM DOING LIKE THIS

    • @vickyorg
      @vickyorg 4 місяці тому

      Commented by looking at the first half sorry !

  • @black_grey3226
    @black_grey3226 4 місяці тому +1

    I just cam r to understand this question.

  • @SantoshKumar2
    @SantoshKumar2 4 місяці тому

    Seems like internship season started in leetcode. 😅

  • @chien-yuyeh9386
    @chien-yuyeh9386 4 місяці тому

    Nice 🎉

  • @olanrewajubakare3790
    @olanrewajubakare3790 4 місяці тому

    Log100 is supposed to be 2 right?

    • @mohd.tabishkhan4868
      @mohd.tabishkhan4868 4 місяці тому

      that is when the base is 10 but in computer science generally the base is taken as 2 because of binary, so log 100 base 2 will be 6.64385618…

    • @olanrewajubakare3790
      @olanrewajubakare3790 4 місяці тому

      @@mohd.tabishkhan4868 You are absolutely right. Don't know why I thought this was actual math.

  • @sarathikumark
    @sarathikumark 4 місяці тому

    Bro leetcode problem no 481 try

  • @fancypants6062
    @fancypants6062 4 місяці тому +4

    2:22 lmao erase that one real quick

  • @mohammedansil2302
    @mohammedansil2302 4 місяці тому

    never try to relate real-world problems with dsa

  • @sarathikumark
    @sarathikumark 4 місяці тому

    Bro

  • @paulfunigga
    @paulfunigga 4 місяці тому

    The solution is not clear or convincing