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

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 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 5 วันที่ผ่านมา

    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.

  • @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

  • @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.

  • @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

  • @kavyanshpandey3823
    @kavyanshpandey3823 4 หลายเดือนก่อน

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

  • @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.

  • @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!

  • @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)

  • @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?

  • @kavyanshpandey3823
    @kavyanshpandey3823 4 หลายเดือนก่อน

    Following you since last 4 month with 95 percent consistency

  • @AnordinaryMan007
    @AnordinaryMan007 4 หลายเดือนก่อน +2

    Thanks for the different approaches.

  • @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.

  • @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

  • @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 😂

  • @kraav4ikk6
    @kraav4ikk6 4 หลายเดือนก่อน

    thank you for different solutions!

  • @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 !

  • @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 😅😂😂😂😂

  • @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.

  • @black_grey3226
    @black_grey3226 4 หลายเดือนก่อน +1

    I just cam r to understand this question.

  • @chien-yuyeh9386
    @chien-yuyeh9386 4 หลายเดือนก่อน

    Nice 🎉

  • @SantoshKumar2
    @SantoshKumar2 4 หลายเดือนก่อน

    Seems like internship season started in leetcode. 😅

  • @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