Find Common Characters | Simple Dry Run | Leetcode 1002 | codestorywithMIK

  Рет қаралды 7,583

codestorywithMIK

codestorywithMIK

Күн бұрын

Whatsapp Community Link : www.whatsapp.c...
This is the 41st Video of our Playlist "Leetcode Easy : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good practice Array+String+Map problem : Find Common Characters | Simple Dry Run | Leetcode 1002 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Find Common Characters | Simple Dry Run | Leetcode 1002 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) : github.com/MAZ...
Leetcode Link : leetcode.com/p...
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My Recursion Concepts Playlist : • Introduction | Recursi...
My GitHub Repo for interview preparation : github.com/MAZ...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
We need to find the common characters in a list of strings. Here's a summary of the approach :
fillCountArray Method: This helper method takes a string and an array of 26 integers (representing counts for each letter of the alphabet). It increments the counts for each character in the string.
commonChars Method:
Initialization: The method initializes a vector of strings (result) to store the common characters and an integer array count of size 26 to keep track of character frequencies in the first word.
Count Update: It calls fillCountArray on the first word to populate count. Then, for each subsequent word, it uses a temporary count array temp to store character frequencies.
Frequency Comparison: For each character, it updates count to the minimum frequency of that character between the current count and temp.
Result Construction: Finally, it iterates over the count array, and for each non-zero count, it adds the corresponding character to the result the number of times it appears.
Return: The method returns the vector of common characters.
In essence, the solution identifies the minimum frequency of each character across all words and constructs the list of common characters based on these frequencies.
✨ Timelines✨
00:00 - Introduction
#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 #newyear2024

Пікірлер: 36
@shivamsingh-mi4mn
@shivamsingh-mi4mn 3 ай бұрын
i just woke and tried the pod of leetcode..but i could not able to solve..so i was waiting for your video .Again You Made my morning....thnku bhaiya
@Sumit-wy4zp
@Sumit-wy4zp 3 ай бұрын
same bro 😔definitely it's not a easy problem
@shivamsingh-mi4mn
@shivamsingh-mi4mn 3 ай бұрын
@@Sumit-wy4zp it was kinda easy problem i got the logic but i wasn't able to code
@shibainu7500
@shibainu7500 3 ай бұрын
OMG I solved the question on my own and my code is ditto same as your.
@nerduser1000
@nerduser1000 3 ай бұрын
guess what been trying this problem from yesterday crazy that IT came as potd today crazy^2 that you made a video about it xd
@dayashankarlakhotia4943
@dayashankarlakhotia4943 3 ай бұрын
Good explanation 👏 👍
@Shivamsingh-ry6bz
@Shivamsingh-ry6bz 3 ай бұрын
2:17 bella
@dibbodas4116
@dibbodas4116 3 ай бұрын
your explanation is so excellent✅
@22gauravkumar70
@22gauravkumar70 3 ай бұрын
bhaiya please segment tree sikha do pls , 1 saal se try kr raha hun sikhne ka aap hi sikha skte ho. ek 3-4 ghnte ki video bna do , 5-6 questions krwa do along with basic code , please bhaiya
@DevSharma-vx3ip
@DevSharma-vx3ip 3 ай бұрын
+1
@prajwalshaw9217
@prajwalshaw9217 3 ай бұрын
+1
@user-vs5rh1oz3w
@user-vs5rh1oz3w 3 ай бұрын
congrats sir for 50k subs. i hope the count will keep going. please take a glance on gfg potd today's as well. a good prefix sum question.
@user-ub2is4rs4x
@user-ub2is4rs4x 3 ай бұрын
I think this could have been marked MEDIUM Its a good one. Thanks for explaining so well
@utkarshsahay9908
@utkarshsahay9908 3 ай бұрын
class Solution { public: vector commonChars(vector& words) { vector cnt(26,0); vector ans; for(int i = 0;i < words[0].size();i++){ cnt[words[0][i] - 'a']++; } for(int i = 1; i < words.size();i++){ string s = words[i]; vector cnt1(26,0); for(char ch : s){ cnt1[ch-'a']++; } for(int j = 0; j < 26; j++){ cnt[j] = min(cnt[j],cnt1[j]); } } for(int i = 0;i < 26;i++){ int no = cnt[i]; while(no--) ans.push_back(string(1,'a'+i)); } return ans; } };❤❤
@PANKAJKUMAR-nx6kv
@PANKAJKUMAR-nx6kv 3 ай бұрын
please bro explain :- 474. Ones and Zeroes question
@gauravbanerjee2898
@gauravbanerjee2898 3 ай бұрын
Thanks a lot Bhaiya ❤❤
@shivanshishrivastava4161
@shivanshishrivastava4161 3 ай бұрын
sir please put the solution of leetcode 3122 .I am stuck with this problem
@unknown47896
@unknown47896 3 ай бұрын
class Solution { public: vector commonChars(vector& words) { int n=words.size(); vector freq(26,0); for(auto ch:words[0]) freq[ch-'a']++; for(int i=1;i
@pokeindia5361
@pokeindia5361 3 ай бұрын
Bhaiya please longest valid parantheses q ka video laiye important q h interview k liye
@AdityaGupta-sw8zr
@AdityaGupta-sw8zr 3 ай бұрын
bhaiya gfg ka potd aur start kardo plz plz Thanks in advance❤❤
@Manjot_singh2002
@Manjot_singh2002 3 ай бұрын
bhaiya apny ye konsa function use kiya in line 31
@codestorywithMIK
@codestorywithMIK 3 ай бұрын
It’s just a way to create a string of length 1 which has character (i+’a’) For example : if you have to create a string of length 1 having character ‘z’ Then you will create like this string(1, ‘z’)
@Avatar40456
@Avatar40456 3 ай бұрын
what is the problem with this code : class Solution { public: void fillcount(string &word,int count[26]) { for(char &c: word) { count[c-'a']++; } } vector commonChars(vector& words) { vectorresult; int n=words.size(); int count[26]={0}; fillcount(words[0],count); for(int i=1;i
@yogeshchauhan9401
@yogeshchauhan9401 3 ай бұрын
In last loop you are only pushing character one time there can be more than one occurence
@jeethora586
@jeethora586 3 ай бұрын
use while instead of if in the last loop whre u r making final string to be returned
@SohailKhan-cx9gb
@SohailKhan-cx9gb 3 ай бұрын
while(cnt[i]!=0){ result.push_back(string(1,i+'a')); cnt[i]--; }
@nishantthakur6366
@nishantthakur6366 2 ай бұрын
bhai or to thik hai pr more pr click krne pr github ka link or whatapp ka link nhi aa rha
@codestorywithMIK
@codestorywithMIK 2 ай бұрын
It’s coming when I click. But let me share here in case you are not able to . My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Leetcode%20Easy/Find%20Common%20Characters.cpp whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A ❤️❤️❤️
@aizad786iqbal
@aizad786iqbal 3 ай бұрын
I wrote this solution on my own strangely this also passed with 4 ms only class Solution { public List commonChars(String[] words) { int n = words.length; List ans = new ArrayList(); int[][] freq = new int[n][26]; for(int i=0;i
@nish0798
@nish0798 3 ай бұрын
BRO PLEASE ANSWER THIS QUESTION QUESTION IS IF WE CAN FORM TARGET STRING FROM ARRYA ELEMENTS import java.util.ArrayList; public class Solution { static ArrayList res = new ArrayList(); // Not used in this version public static void main(String[] args) { String[] arr = {"os","mn","pqr","qr"}; String t = "pqros"; //THIS SHOULD RETURN TRUE BCOZ PQR+OS is forming target but it is giivng false should return true technically String sofar = ""; ArrayList l = new ArrayList(); System.out.println(canconst(arr, t, sofar, 0, l)); } public static boolean canconst(String[] arr, String t, String sofar, int idx, ArrayList l) { if(sofar.equals(t)) { return true; } if (idx >= arr.length) { return false; } // Try appending each string from arr to sofar and recursively check if (canconst(arr, t, sofar + arr[idx], idx+1 , l)) { return true; } return canconst(arr, t, sofar, idx + 1, l); } } //THIS SHOULD RETURN TRUE BCOZ PQR+OS is forming target but it is giivng false should return true technically this code is only giivng correct output if the we are checking the idx elements sequence wise why so please answer what changes should i make in my code so that it works galti pakad nai aa rahi please help bhai do ghante ho gaye hit and trial kar raha hu doubt clear kardo aisa kyu horaha hai pLEASE DO REPLY ITS A REQUEST
@sunilsarode152
@sunilsarode152 3 ай бұрын
class Solution { public: vector commonChars(vector& words) { int n=words.size(); vector ans; for(int i=0;i
@jk-sm6qr
@jk-sm6qr 3 ай бұрын
👍
@Mohit-fe5hx
@Mohit-fe5hx 3 ай бұрын
any other method of this question to solve???
@c00per_
@c00per_ 3 ай бұрын
What's the efficient approach
@rohitaggarwal8776
@rohitaggarwal8776 3 ай бұрын
This is definitely not a easy question
Spiral Matrix - Microsoft Interview Question - Leetcode 54
16:46
大家都拉出了什么#小丑 #shorts
00:35
好人小丑
Рет қаралды 84 МЛН
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 211 МЛН
МЕБЕЛЬ ВЫДАСТ СОТРУДНИКАМ ПОЛИЦИИ ТАБЕЛЬНУЮ МЕБЕЛЬ
00:20
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 2 МЛН
NextJs - Beginner to Master - Class 08
1:35:00
Awais Akhter
Рет қаралды 186
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 207 М.
Cursor Is Beating VS Code (...by forking it)
18:00
Theo - t3․gg
Рет қаралды 41 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 498 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 280 М.
Harder Than It Seems? 5 Minute Timer in C++
20:10
The Cherno
Рет қаралды 169 М.
大家都拉出了什么#小丑 #shorts
00:35
好人小丑
Рет қаралды 84 МЛН