Word Subsets | Leetcode 916

  Рет қаралды 4,491

Techdose

Techdose

Күн бұрын

This video explains word subsets problem using the the most optimal hashmap approach.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037
🟣 𝐂𝐡𝐞𝐜𝐤𝐨𝐮𝐭 𝐚𝐥𝐥 𝐨𝐮𝐫 𝐂𝐨𝐮𝐫𝐬𝐞𝐬: techdose.co.in/
🔵 LinkedIn: / surya-pratap-kahar
🔴 INSTAGRAM: / techdose_official
🟢 𝐓𝐞𝐜𝐡𝐝𝐨𝐬𝐞-𝟏𝟎𝟎 𝐬𝐡𝐞𝐞𝐭: docs.google.co...
---------------------------------------------------------------------------------------------------------------------------------------------------------------
𝐂𝐎𝐃𝐄 𝐋𝐈𝐍𝐊: gist.github.co...

Пікірлер: 13
@divyanshsharma1694
@divyanshsharma1694 28 күн бұрын
Very nicely explained, thank you sir!
@techdose4u
@techdose4u 28 күн бұрын
Glad it was helpful!
@divyasingh6771
@divyasingh6771 29 күн бұрын
Thank you sir for the solution. I did it with hashmap . This is my code:-class Solution { public static MapgetfrequencyMap(String str) { Map frequencyMap=new HashMap(); for(char c:str.toCharArray()) { frequencyMap.put(c,frequencyMap.getOrDefault(c,0)+1); } return frequencyMap; } public List wordSubsets(String[] words1, String[] words2) { List result=new ArrayList(); Map subset=new HashMap(); for(String word:words2) { Map part=getfrequencyMap(word); for(Map.Entry entry:part.entrySet()) { char key=entry.getKey(); int count=entry.getValue(); subset.put(key,Math.max(subset.getOrDefault(key,0),count)); } } for(String Word:words1) { Map wordFreqMap=getfrequencyMap(Word); int sum=0; for(Map.Entry entry:subset.entrySet()) { char key=entry.getKey(); int count=entry.getValue(); if(wordFreqMap.getOrDefault(key, 0)
@anaghabharadwaj3586
@anaghabharadwaj3586 29 күн бұрын
Thank you sir , well explained.
@techdose4u
@techdose4u 29 күн бұрын
welcome :)
@rakshitshandilya9934
@rakshitshandilya9934 29 күн бұрын
I think we can do word2 operations on a single map also
@Anikait-h3d
@Anikait-h3d 29 күн бұрын
first week is always full of easy questions. Difficult question ana chalu hone hi wala hai
@techdose4u
@techdose4u 29 күн бұрын
hoping for harder ones :)
@bhavukkalra1786
@bhavukkalra1786 29 күн бұрын
what is the reasoning for the usage of the array to keep track of the number of instances of the characters? The same can be accomplished using maps right?
@techdose4u
@techdose4u 29 күн бұрын
array is the map :) array is faster on runtime while maps are slower
@bhavukkalra1786
@bhavukkalra1786 28 күн бұрын
@ hey thanks for taking the time out replying. Correct, I did went on and changed the map implementation for tracking the max character count in word2 and my solution was finally out of the TLE. Its crazy on how such a minor DS change can make or break a solution. Thanks for the video once again, It is due to your video that my streak is still alive hehe😎
@Marvel9-j4d
@Marvel9-j4d 29 күн бұрын
🎉🎉🎉🎉
@techdose4u
@techdose4u 29 күн бұрын
🎉
Maximum Employees to Be Invited to a Meeting | Leetcode 2127
52:53
Check if a Parentheses String Can Be Valid | Leetcode 2116
25:49
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
916. Word Subsets | Hash Map | Strings
14:44
Aryan Mittal
Рет қаралды 2 М.
Design a Number Container System | Leetcode 2349
18:00
Techdose
Рет қаралды 5 М.
Divide Nodes Into the Maximum Number of Groups | Leetcode 2493
34:11
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 811 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 920 М.
L1. Introduction to LinkedList | Traversal | Length | Search an Element
45:17
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 276 М.
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН