First Completely Painted Row or Column - Leetcode 2661 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

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

  • @yang5843
    @yang5843 14 ชั่วโมงที่ผ่านมา +26

    This one is not filmed in a car

  • @qsvui
    @qsvui 13 ชั่วโมงที่ผ่านมา +14

    "hashmap-jutsu" lol

  • @dhaneshvenkateslu8638
    @dhaneshvenkateslu8638 12 ชั่วโมงที่ผ่านมา +6

    I can see progress,I came up with the same solution as yours

  • @skanderbegvictor6487
    @skanderbegvictor6487 13 ชั่วโมงที่ผ่านมา +5

    Solved it on my own using hashmaps and arrays

    • @abdulrehmanansari2332
      @abdulrehmanansari2332 10 ชั่วโมงที่ผ่านมา

      great
      i got stuck at the part how can i check if row or col is fully colored efficiently

    • @hussainkazia2047
      @hussainkazia2047 4 ชั่วโมงที่ผ่านมา +1

      Take the two arrays, rows of matSize and cold of matColSize. for each iteration inrement the ith row value and jth col value.

    • @skanderbegvictor6487
      @skanderbegvictor6487 2 ชั่วโมงที่ผ่านมา

      @ yes I was able to solve it

  • @Papa_Static
    @Papa_Static 2 ชั่วโมงที่ผ่านมา

    My initial solution was very similar to this, except I used sets for the rows and columns and my hashmap was val: (row,col) instead of (row,col) : val. After seeing it pass, I realized the sets were overkill and came up with the row/column count solution. Really glad to see it was very similar!

  • @yhbarve
    @yhbarve 14 ชั่วโมงที่ผ่านมา +3

    This was a easy problem

    • @baetz2
      @baetz2 13 ชั่วโมงที่ผ่านมา +1

      easy to bruteforce, not so easy to come up with optimal solution. I've created a collection of hashsets for each row and each column and iterated through arr and deleted the value from the hashsets. Then returned the index as soon as found first empty hashset. Unfortunately, it was too slow

    • @anhdtran95
      @anhdtran95 13 ชั่วโมงที่ผ่านมา +1

      ​@@baetz2 Since arr contains unique values. You can just keep a count and decrement for each row and col. Whichever reaches 0 first you can return the index of arr.

    • @staywithmeforever
      @staywithmeforever 13 ชั่วโมงที่ผ่านมา +2

      ​@@baetz2 i don't agree it's easy just think how can I get value while traversing in arr u can get the idea of row and column sum so its a easy problem.

  • @ABEFOOTBALLTV
    @ABEFOOTBALLTV 4 ชั่วโมงที่ผ่านมา

    Did it by taking sum of each row and column then decreasing it as we iterate through array.
    class Solution(object):
    def firstCompleteIndex(self, arr, mat):
    """
    :type arr: List[int]
    :type mat: List[List[int]]
    :rtype: int
    """
    #hsum = [0]*len(mat)
    hsum = defaultdict(int)
    #for i in range(len(mat)):
    # hsum[i]=sum(mat[i])

    #vsum = [0]*len(mat[0])
    vsum = defaultdict(int)
    #for j in range(len(mat[0])):
    #for k in mat:
    #vsum[j]+=k[j]

    mymap = {}
    test1 = 0
    for row in range(len(mat)):
    #hsum[row]=sum(mat[row]) //Trying to get it speed up
    for col in range(len(mat[0])):
    mymap[mat[row][col]] = [row,col]
    hsum[row]+=mat[row][col]
    if test1==0:
    for k in mat:
    vsum[col]+=k[col]
    test1 =1

    for i in arr:
    r = mymap[i][0]
    c = mymap[i][1]
    hsum[r]-=i
    vsum[c]-=i
    if hsum[r]==0 or vsum[c]==0:
    return arr.index(i)

  • @staywithmeforever
    @staywithmeforever 13 ชั่วโมงที่ผ่านมา +1

    Why list for column and row takes less time than dictionary for row and column

    • @staywithmeforever
      @staywithmeforever 13 ชั่วโมงที่ผ่านมา +1

      Is accessing by index that fast than in dict

    • @harishramaswamy1
      @harishramaswamy1 5 ชั่วโมงที่ผ่านมา

      @@staywithmeforever Storing in arrays instead of dictionaries prevents hash collisions I guess

    • @staywithmeforever
      @staywithmeforever 5 ชั่วโมงที่ผ่านมา

      @@harishramaswamy1 collisions don't even occur the column and row are unique.

  • @KrishnaReddy-yt9nt
    @KrishnaReddy-yt9nt 13 ชั่วโมงที่ผ่านมา +2

    Let's get the car back 😂

  • @gokulsaravanan1696
    @gokulsaravanan1696 9 ชั่วโมงที่ผ่านมา +1

    I still have doubt , the given constraint is m

    • @harshanarnepati8840
      @harshanarnepati8840 7 ชั่วโมงที่ผ่านมา

      they would also give that m*n is less than 10*5 or something if u check the constraints

  • @shadowalphawolf9926
    @shadowalphawolf9926 8 ชั่วโมงที่ผ่านมา +1

    Holy shit I came up with the exact same solution as you. Proud moment for me 😆

    • @NeetCodeIO
      @NeetCodeIO  ชั่วโมงที่ผ่านมา

      Nice job

  • @markopolo2224
    @markopolo2224 13 ชั่วโมงที่ผ่านมา +1

    just solved that one lol

  • @mohdzaheer9247
    @mohdzaheer9247 10 ชั่วโมงที่ผ่านมา +1

    29. Divide Two Integers medium of LEETCODE DO Solve This Brother

  • @hussainkazia2047
    @hussainkazia2047 4 ชั่วโมงที่ผ่านมา

    Now we can write the code for x and o game.

  • @sumedhganpatye2575
    @sumedhganpatye2575 6 ชั่วโมงที่ผ่านมา

    I can see progress in myself. Got the exact same solution as yours.!
    But I thought I would find here a better solution. Anyways I'm happy ;)

  • @shramandas2721
    @shramandas2721 5 ชั่วโมงที่ผ่านมา

    y no car