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!
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
@@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.
@@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.
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)
This one is not filmed in a car
May be he is done with your mom
"hashmap-jutsu" lol
I can see progress,I came up with the same solution as yours
Solved it on my own using hashmaps and arrays
great
i got stuck at the part how can i check if row or col is fully colored efficiently
Take the two arrays, rows of matSize and cold of matColSize. for each iteration inrement the ith row value and jth col value.
@ yes I was able to solve it
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!
This was a easy problem
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
@@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.
@@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.
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)
Why list for column and row takes less time than dictionary for row and column
Is accessing by index that fast than in dict
@@staywithmeforever Storing in arrays instead of dictionaries prevents hash collisions I guess
@@harishramaswamy1 collisions don't even occur the column and row are unique.
Let's get the car back 😂
I still have doubt , the given constraint is m
they would also give that m*n is less than 10*5 or something if u check the constraints
Holy shit I came up with the exact same solution as you. Proud moment for me 😆
Nice job
just solved that one lol
29. Divide Two Integers medium of LEETCODE DO Solve This Brother
Now we can write the code for x and o game.
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 ;)
y no car