Minimum Domino Rotations for Equal Row - Leetcode 1007 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2024

ความคิดเห็น • 26

  • @NeetCode
    @NeetCode  2 ปีที่แล้ว +9

    Btw this was identified as a Google question from leetcode 😛: leetcode.com/discuss/interview-question/352460/Google-Online-Assessment-Questions

    • @masternobody1896
      @masternobody1896 2 ปีที่แล้ว

      can you tell me why am i not getting a job on fang

    • @masternobody1896
      @masternobody1896 2 ปีที่แล้ว

      been unemployed for 2 years rip :(

  • @numberonep5404
    @numberonep5404 2 ปีที่แล้ว +6

    I audibly said "oh yes!" when i saw you posted a new video on a sunday, english is not even my native language xD Keep up the good work man!

  • @ShikaIE
    @ShikaIE 2 ปีที่แล้ว +7

    Hey neet, would you be able to share how’s the usage of any algorithms in your day to day work at google. Curious to know whether do you guys really talk about big O in code review, etc.
    For starters, i work with a lot of graphs algo day to day :)

  • @ShouryanNikam
    @ShouryanNikam 2 ปีที่แล้ว +2

    Hey man, congratulations on your new job! I hope that you keep making these videos in your spare time. There is no current channel that provides your quality of explanations in Python.

  • @bernardpark3196
    @bernardpark3196 2 ปีที่แล้ว

    Hey NeetCode - just wanted to say thanks so much for the videos you've put out. I have been watching you for the last year and you've really helped me with my prep as well as my confidence.
    I was offered a job to a great company the other day, and I can definitely say you were a large part of why I was able to pass the interview.
    Thank you again! Truly appreciate the effort you've put in.

  • @nicolasrodriguezjeangros8577
    @nicolasrodriguezjeangros8577 2 ปีที่แล้ว

    Thanks for all the videos. One quick question. I know you use a nice drawing pad for all your videos. Did you/were you allowed to use it during the interview? If not, what did you use to draw conceptual figures such as a tree? Thanks again!

  • @PrashantKumar-rx5rn
    @PrashantKumar-rx5rn 2 ปีที่แล้ว +1

    Thanks NeetCode for providing such contents

  • @mystril8001
    @mystril8001 2 ปีที่แล้ว

    Hey! Just came here to say that u do awesome job. I found one of your videos while searching for some explaination of dynamic algorithms and subscribed immidiately. Thanks for all the work u do for us.

  • @ishysticks
    @ishysticks 2 ปีที่แล้ว +1

    Hey Neet,
    could you go over LeetCode #109, Convert Sorted List to BST? Thanks!

  • @staffeng
    @staffeng 2 ปีที่แล้ว

    @NeetCode - can you tell us if you had to peek at the solution or if you figured this out on your own? How does one even come up with a O(2n) solution without either spending a great deal of time on the problem or being a complete genius?
    This is an unusually harder problem that looks very simple at first. I found two places in the code harder/unintuitive to understand but it made sense after looking at it with fresh eyes :)
    One: the reason why we take only the first top and bottom as targets is because if they aren't there in the rest of the indices in either of the arrays, the result is a -1.
    Two: the return statement in the inner for-loop. This was harder than the first one. I kept thinking why is he returning without exhausting the processing for both the targets! But the only way the top[0] (target 1) reaches till the end is if it was present at all the indices of either of the arrays, but it also means the bottom[0] (target 2) which is still unexplored is either the same as top[0] or it is **not** present at all the indices in either of the arrays.
    I may find this harder to understand again if I look at this problem after 2 years. I think anyone can come up with a O(6n) solution but it takes special talent to come up with a O(2n) solution.

  • @costitica
    @costitica 2 ปีที่แล้ว

    My solution: have a list of pairs of size 7 (let's call it 'count') for counting how many different distinct positions in top/bottom (first pos in pair/second pos in pair) lists contain the index i in count (value on one piece of domino).
    In the end iterate through the 'count' list and if the sum of the values in the pair is equal to the length of the top/bottom lists, then update the minimun number of rotations with min(len(top) - max(count[i][0], count[i][1]), numMinRot)

  • @curimeowcat6957
    @curimeowcat6957 2 ปีที่แล้ว

    Hi @Neetcode, I really liked your videos! It's great to see you illustrating the solution in such a neet and easy to understand way! I would also appreciate you if you can also make similar videos to Google Code Jam problems, which are also very difficult but very interesting!

  • @hammadmaya7109
    @hammadmaya7109 2 ปีที่แล้ว

    Hi Thank you for making all the videos you do! It really helped me learn and retain the information. Could you do a video on 2104. Sum of Subarray Ranges. It seems to be fairly new and I cannot figure out the solution that makes sense to me

  • @aodirary
    @aodirary 2 ปีที่แล้ว

    Hey Neetcode, can you do LeetCode 314, since it is a pie number and you never done that?

  • @kimeiga
    @kimeiga ปีที่แล้ว

    class Solution:
    def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:
    def rotations_to_make_equal(target, A, B):
    """Returns the number of rotations required to make all of A equal to target.
    Uses B for possible rotations. If it's not possible, returns float('inf')."""
    rotations = 0
    for i in range(len(A)):
    if A[i] != target and B[i] != target: # Cannot make this domino equal to target
    return float('inf')
    if A[i] != target: # Need to rotate this domino
    rotations += 1
    return rotations
    # Calculate the minimum rotations required for each number from 1 to 6
    min_rotations = float('inf')
    for num in range(1, 7):
    min_rotations = min(min_rotations, rotations_to_make_equal(num, tops, bottoms))
    min_rotations = min(min_rotations, rotations_to_make_equal(num, bottoms, tops))
    # If no valid rotations are found, return -1
    return min_rotations if min_rotations != float('inf') else -1

  • @gabrielacuna8530
    @gabrielacuna8530 2 ปีที่แล้ว

    Hey I mentioned you in my LinkedIn post! Thank you for your help man, you helped me get into FAANG!! Connect with me there, I owe you a drink!

  • @Yashas-z9s
    @Yashas-z9s 2 ปีที่แล้ว +1

    Love u sir

  • @JacobAuthier
    @JacobAuthier 2 ปีที่แล้ว

    You should do 399. Evaluate Division ;)

  • @chaitanyakhot3842
    @chaitanyakhot3842 2 ปีที่แล้ว

    8:14 what is the shortcut for tab spacing multiple lines?

    • @chandra3370
      @chandra3370 2 ปีที่แล้ว

      Select all these lines and just press tab button.

    • @cc-to2jn
      @cc-to2jn 2 ปีที่แล้ว

      And to do the reverse, hold shift+tab

    • @chaitanyakhot3842
      @chaitanyakhot3842 2 ปีที่แล้ว

      Thanks guys

  • @matancohen6098
    @matancohen6098 2 ปีที่แล้ว

    Have you ever heard of PEP8?!

  • @naveenprasanthsa3749
    @naveenprasanthsa3749 2 ปีที่แล้ว

    7:46 lol