merging the max of hashmaps was the input i needed
@MihirPande-b6zСағат бұрын
Nice, was able to do with some hints, Thanks neetcode
@danillogunov26293 сағат бұрын
Hi. You can use for-else case instead of a flag to check if loop ended naturally and not broke out. Just replace if flag with else and that's it Thanks for videos!
@chrisadjei264052 минут бұрын
Spent the entire day trying to figure it out lol. Great explanation!!!
@anantakesharipanda408511 сағат бұрын
Seemed easy, but got stuck in nitty gritties while implementing it. Thanks for posting the solution, Navdeep!
@irfan.s561610 сағат бұрын
his name is Navdeep?
@anantakesharipanda40859 сағат бұрын
@ Yes, his LinkedIn profile is in the video description.
@business_central4 сағат бұрын
I am proud I found the solution by myself. Thank you Neet! If anything I also converted words1 and words2 to sets to avoid duplicate words
@vitruvius12024 сағат бұрын
Got stuck with implementing the hashes. Great explanation. Biggest takeaway for me was how I can use the .get() method for dictionaries
@yang584310 сағат бұрын
The trick was to combine the Max chars of word2
@harishramaswamy17 сағат бұрын
you can directly use else with for instead of using flags in Python If loop exits normally the only then the else part runs
@chiragaparadh141711 сағат бұрын
solved it in 11:11 minutes
@sleepypixie882851 минут бұрын
how do you get the intuition man, i feel so dumb sometimes when I'm absolutely stuck after applying the brute force solution to any problem. It's like ok here's the brute force, now what do i do? and then i proceed to stare at the problem
@prajwals82034 сағат бұрын
Your voice was strange today? Are you alright?
@akhi_java11 сағат бұрын
Let's go! :)
@ABEFOOTBALLTV2 сағат бұрын
i like doing the hashmap stuff by myself :) ans = [] mymap2 = defaultdict(int) for word in words2: mymap = {} for c in word: if c in mymap: mymap[c]+=1 else: mymap[c]=1 for ch in word: mymap2[ch] = max(mymap[ch],mymap2[ch]) lenm = len(mymap2) for i in range(len(words1)): mymap1 = {} for s in words1[i]: if s in mymap1: mymap1[s]+=1 else: mymap1[s]=1 counta = 0 for x in mymap2: if x in mymap1 and mymap1[x]>=mymap2[x] : counta+=1 if counta == lenm: ans.append(words1[i]) return ans
@rhitambhuiya40885 сағат бұрын
if all(count_w[char] >= freq for char, freq in count_2.items()): universal.append(w) This provides a more concise approach in Python, instead of using the flag variable.
@thenova2254 сағат бұрын
Although it is more pythonic, it makes unnecessary checks especially when inputs are large
@BVijay-tq3je9 сағат бұрын
I tried to solve it like this class Solution: def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]: a=words2[0] b=words2[1] op=[] for i in words1: if ((a and b) in i)): op.append(i) return op this kinda worked intitially but failed the rest of the testcases,
@qulinxao6 сағат бұрын
def wordSubsets(self, U: List[str], B: List[str]) -> List[str]: B=[Counter(b)for b in B] ; K=set.union(*(set(b)for b in B)) ; C=Counter({k:max(b[k]for b in B)for k in K}); nonbigger=lambda e: all(e[k]-v>=0 for k,v in C.items()) #def nonbigger(e): return all(e[k]-v>=0 for k,v in C.items()) return [u for u in U if nonbigger(Counter(u))]
@yashshukla163711 сағат бұрын
Question was very easy
@KarthiKarthi-df2mp11 сағат бұрын
Its 12.27 in india....waited for 6 hrs....Thanks for the solution