Word Subsets | Simple Thought Process | C++ | Java | Leetcode 916 | codestorywithMIK

preview_player
Показать описание

Hi Everyone, this is the 56th video of our Playlist "Strings : Popular Interview Problems".
Now we will be solving a good practice problem based on map and string - Word Subsets | Simple Thought Process | C++ | Java | Leetcode 916 | codestorywithMIK
Since this is a fairly small problem, hence I will also code it in Java in the video itself. Hope that helps.

Problem Name : Word Subsets | Simple Thought Process | C++ | Java | Leetcode 916 | codestorywithMIK
Company Tags : Amazon, Google

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Video Summary :
This approach determines the universal strings in words1 by comparing character frequencies. Here's a breakdown:

Calculate Maximum Character Frequencies for words2:

Iterate through each string in words2.
Use a temporary frequency array (temp) to count the occurrences of each character in the current string.
Update a global frequency array (freq2) to store the maximum frequency of each character across all strings in words2.
Check Each String in words1:

For each string in words1, calculate its character frequency using a temporary array (temp).
Compare the frequencies in temp with freq2 using the isSubset helper function.
If temp satisfies the subset condition, add the string to the result.
Helper Function (isSubset):

Compares two frequency arrays and ensures that for each character, the frequency in temp is at least as much as in freq2.
Key Insight:

By precomputing the maximum frequency requirements for words2, the algorithm efficiently checks each string in words1 for universality without redundant computations.

✨ Timelines✨
00:00 - Introduction
00:17 - Motivation
01:35 - Problem Explanation
05:25 - Thought Process with examples
11:36 - Small Dry Run
16:11 - Coding in C++
23:27 - Coding in JAVA

#MIK #mik #Mik
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik
Рекомендации по теме
Комментарии
Автор

Good morning Sir,
Tomorrow's Motivation from my side :- Consistency and discipline are the bridges between goals and accomplishments.

shreyaawasthi
Автор

Thanks a lot for JAVA code.
I got stuck in the max frequency part, as soon as you explained "oo" wala case, it triggered me and solved it immediately. Thanks a lot

gui-codes
Автор

Thanks a lot for bringing Java code ❤❤

italk-gjkk
Автор

9:04 me video pause kiya and sab samajh agaya and coded it.
Beautifully explained. You have proved that you are the best tutor of DSA on youtube

EB-otuu
Автор

When you want something bad enough you don't question whether the effort is worth it. You just put in the effort.

compidemail
Автор

80K soon. Congratulations in advance. Soon you will hit Millions. You are doing an amazing work.

wearevacationuncoverers
Автор

Chalo
Kaam pr chalta hai mik bhaiya agar consistent hai toh hum kuu nhi

jain
Автор

Motivation- Days are Foggy but Don't be lazy like Doggy 👌👌👌👌

vaibhav
Автор

Hello MIK, kindly make a video on "Meet in the middle" algorithm

ConvxO
Автор

I’m asking about the interview and placement perspective for company.
Bhaiya, I am a C++ and Python coder. I know Java at a basic to medium level but am not able to use it for competitive coding. Is it necessary for me to learn Java more for coding as well? Personally, I hate writing programs in Java. It was a subject in my BTech, so I’ve done it, but nothing more than that.

and can you bring video like " programming lang. and other tools/software and it's usecases in IT industry ". in detail.

Please Request

Thank you ❤🙏

gorasiyakashyap
Автор

Only consistency transforms Average into Excellence..

shaiksameerbasha
Автор

Python implementation:
class Solution:
def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:
reqFreq = [0]*26

for word in words2:
cur = Counter(word)

for i in range(26):
if chr(i+ord('a')) in cur:
reqFreq[i] = max(reqFreq[i], cur[chr(i+ord('a'))])

res = []

for word in words1:
curCounter = Counter(word)
possible = True

for i in range(26):
if reqFreq[i] == 0:
continue

if (
chr(i+ord('a')) not in curCounter or
curCounter[chr(i+ord('a'))] < reqFreq[i]
):
possible = False
continue

if possible:
res.append(word)

return res

sauravchandra
Автор

this is how i solved this question sir :

class Solution {
public:
bool check(vector<int>& mp1, vector<int>& mp2){
for(int i=0;i<26;i++){
if(mp1[i] == 0){
continue;
}
if(mp2[i] < mp1[i]){
return false;
}
}
return true;
}
vector<string> wordSubsets(vector<string>& words1, vector<string>& words2) {
vector<string>result;

vector<int>mp1(26, 0);
for(auto& word : words2){
vector<int>temp(26, 0);
for(int i=0;i<word.size();i++){
temp[word[i]-'a']++;
}
for(int i=0;i<26;i++){
mp1[i] = max(mp1[i], temp[i]);
}
}

for(auto& word : words1){
vector<int>mp2(26, 0);
for(int i=0;i<word.size();i++){
mp2[word[i]-'a']++;
}
if(check(mp1, mp2)){
result.push_back(word);
}
}

return result;

}
};

vishwashsoni
Автор

bhaiya aasa he java me bhi solution batya kariya c++ ke sath sath..🙏🏻🙏🏻🙏🏻

AkashKumar
Автор

Hello MIK,
I really need your advise. I am going to appear in the fourth and final round of a big tech mnc. The feedback that I received from the previous three rounds was that I eventually come up with approach and code, but was not able to handle edge cases and corner cases. I have roughly 4-5 days left to prepare. Could be please suggest a strategy of what and how to prepare in this final stage. I am following your channel from past 1 year. Any advise would be much appreciated🙏🙏🙏

KG-tscz
Автор

I was not able to understand the eg test cases 😢

bhuppidhamii
Автор

Sir can we solve this question using Trie, by inputting all words in word1 then search word2 alphabets in trie using and where condition satisfied store them in separate vector though TC and SC will be high and not optimal solution

manpanpanman
Автор

one doubt : assume maxf[i]=10 and charfreq [i]=10then it mean both have equal on of char and it pass given criteria

ayushvermaverma
Автор

question me subset bola hai but order is ignored description is misleading

adityatiwari
Автор

Freq alone CANNOT guarantee the subsequence... bcoz it is not mandatory that it will take care of relative order of the words .... Ex- if we need to search for 'wrr' but string is 'rawr' we cannot say it as subsequence

vaibhav