Count Occurrences of Anagrams | Made Super Easy | Amazon | Microsoft | Flipkart | codestorywithMIK

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • This is the first video on Sliding Window Playlist .
    We will be going through Sliding Window in the easiest way possible and will make it one of the easiest topics.
    Today, we will do our very first Qn 'Count Occurrences of Anagrams'
    Problem Name : Count Occurences of Anagrams
    GfG Link : practice.geeks...
    My solutions on Github : github.com/MAZ...
    Company Tags 😱🤯 : Amazon, Intuit, Microsoft, Flipkart
    My GitHub Repo for interview preparation : github.com/MAZ...
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    #coding #helpajobseeker #easyrecipes
    #interviewpreparation #interview_ds_algo #hinglish

Комментарии • 62

  • @jawwadumar2100
    @jawwadumar2100 Год назад +19

    this channel is a hidden gem

  • @mohammedparwezalam5383
    @mohammedparwezalam5383 Год назад +5

    No one explaining like you bro in RUclips...mind blowing..I m fan of you bro..

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      Thank you so much Parwez ❤️❤️❤️
      Means a lot

  • @itzakkhu4378
    @itzakkhu4378 19 дней назад +1

    amazing explanation, i watched around 3-4 videos but this explanation hits my mind thanks! keep uploading!!

  • @GAMERBOY-vu6wt
    @GAMERBOY-vu6wt Год назад +3

    i am now addicted to your channel bro. Thanks for providing all this

  • @ankitshaw_3060
    @ankitshaw_3060 Год назад +3

    Already solved the problem by my own just came here to listen to your story😅😅

  • @chiragsingh8323
    @chiragsingh8323 9 месяцев назад +4

    Add more Videos MIK Bro in this playlist❤
    I know u upload on the basis of daily challenges but still try if u can 😄😊
    Was able to solve it on my own

  • @wearevacationuncoverers
    @wearevacationuncoverers Год назад +2

    MOST UNDERRATED channel ever ❣❣

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 9 месяцев назад +2

    Started this playlist today. Will binge watch 🫡❤️

  • @user-jc7dx7wu5p
    @user-jc7dx7wu5p 10 месяцев назад +2

    Wow! kudos bhai badhiya pdh rhe ho

  • @souravjoshi2293
    @souravjoshi2293 Год назад +2

    This is the best explanation man. Thanks a lot

  • @naman6086
    @naman6086 Месяц назад +1

    froxx mai counter array mai x ki bhi frequecy bdri hai wo kaise handle hoora hai

  • @gaurangshroff
    @gaurangshroff Год назад +1

    best explanation of this problem 💯

  • @Manishgupta200
    @Manishgupta200 Год назад +1

    That's very easy to understand. Thankyou

  • @nishigandhagirishdandekar1131
    @nishigandhagirishdandekar1131 7 месяцев назад

    Very good explanation! Please create a video of how to calculate the TC of different data structures and its application in coding problems

  • @shreyash_17_
    @shreyash_17_ 6 месяцев назад +3

    bhaiya done with leetcode easy and 2 pointers starting with sliding window playlist .

  • @loficlub963
    @loficlub963 Год назад +1

    what a explanation broooo❤❤❤❤❤❤

  • @girikgarg8
    @girikgarg8 11 месяцев назад +1

    Nicely explained

  • @UECAshutoshKumar
    @UECAshutoshKumar 5 месяцев назад +3

    Thank you 👍

  • @ZilaGhaziabad99
    @ZilaGhaziabad99 6 месяцев назад +2

    Another Code: Same Approach (Sliding window)
    int search(string pat, string txt) {
    vector pcnt(26,0);
    vector tcnt(26,0);
    int k = pat.length();
    for(char &ch: pat){
    pcnt[ch-'a']++;
    }
    int i=0,j=0,n=txt.length();
    int ans=0;
    while(j

  • @aws_handles
    @aws_handles 7 месяцев назад

    Legend ❤

  • @piyushacharya7696
    @piyushacharya7696 Год назад +3

    reach++

  • @simnidhnidh9122
    @simnidhnidh9122 22 дня назад

    sir pta kse chala that its sliding window ques pls include these concepts in videos

  • @tusharsharma7293
    @tusharsharma7293 Год назад +1

    Why i am Getting TLE on using unordered map instead of array??

  • @jagadeeshp1163
    @jagadeeshp1163 10 месяцев назад +1

    def check(self,counter):
    for i in counter:
    if i!=0:
    return 0
    return 1
    def findAnagrams(self, s: str, p: str) -> List[int]:
    k=len(p)
    ans=[]
    counter=[0 for i in range(26)]
    for i in p:
    counter[ord(i)-ord('a')]+=1
    i=0
    for j in range(len(s)):
    counter[ord(s[j])-ord('a')]-=1
    while(j-i+1==k):
    if self.check(counter):
    ans.append(i)
    counter[ord(s[i])-ord('a')]+=1
    i+=1
    return ans
    using o(26) frequency array done ✅

  • @AmanVerma-ke8qv
    @AmanVerma-ke8qv Год назад +1

    Good explanation , but not select colour.. or edit that part .. it will be good for eyes

  • @ulhasch1969
    @ulhasch1969 7 месяцев назад

    as per this logic, Here you are updating the counter even for chars which are not in the pattern. should we check if that character is part of pattern first

    • @gurpreet8860
      @gurpreet8860 6 месяцев назад

      We need to decrement counter even if that character isn't in pattern since that window is invalid. The character not in pattern will make the freq/counter for that character negative. Hence, that window will never contribute to ans since all zero will return false in that case which is right since that window isn't anagram of pattern. A window of size patternSize (k) is valid anagram only if allZero returns true for it.

  • @abhishek_singh512
    @abhishek_singh512 Год назад +1

    Please add java code in all videos most of us are using c++ and java in implementing in DSA .

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      Noted Abhishek.
      Generally me or one of my subscribers J J put the Java code from now on always in the comment section

    • @abhishek_singh512
      @abhishek_singh512 Год назад

      @@codestorywithMIK Thanks you always put java code also 🙏

    • @LoremLorem-sm4ub
      @LoremLorem-sm4ub Год назад

      import java.util.Arrays;
      class Solution {
      public static boolean allZero(int[] count) {
      return Arrays.equals(count, new int[26]);
      }
      public static int search(String pat, String txt) {
      int k = pat.length();
      int[] count = new int[26];
      for (char ch : pat.toCharArray()) {
      count[ch - 'a']++;
      }
      int i = 0, j = 0;
      int n = txt.length();
      int result = 0;
      while (j < n) {
      int idx = txt.charAt(j) - 'a';
      count[idx]--;
      if (j - i + 1 == k) {
      if (allZero(count)) {
      result++;
      }
      count[txt.charAt(i) - 'a']++;
      i++;
      }
      j++;
      }
      return result;
      }
      }

  • @jagadeeshp1163
    @jagadeeshp1163 10 месяцев назад +1

    d={}
    map={}
    for i in p:
    d[i]=d.get(i,0)+1
    for i in d:
    map[i]=0
    i=0
    ans=[]
    for j in range(len(s)):
    if s[j] in map:
    map[s[j]]+=1
    while(j-i+1==len(p)):
    if map==d:
    ans.append(i)
    if s[i] in map:
    map[s[i]]-=1
    i+=1
    return ans
    Done :) using hashmap

  • @smsyd853
    @smsyd853 5 месяцев назад

    thank you boos just watched your video and solved a simillar problem in leetcode .
    hats off @codestorywithMIK

  • @anushkathakur6531
    @anushkathakur6531 11 месяцев назад

    Bhaiya,what is the time complexity for the better solution,how is it better than the brute force

  • @mdabrarkhan1943
    @mdabrarkhan1943 6 месяцев назад

    bhaiya leetcode ka bhi question link diya kariye

    • @codestorywithMIK
      @codestorywithMIK  6 месяцев назад

      Sure. I always add Leetcode and gfg link as well in my current videos. Let me add for this too

  • @croxzoxcreation2555
    @croxzoxcreation2555 Год назад

    what is the time complexity of sliding widow approach

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      The time complexity is linear O(n)
      Inside the for loop we call allZero() which will take constant time as we only compare for 26 sized array for 26 alphabets which is constant.
      So overall complexity remains O(n)

    • @croxzoxcreation2555
      @croxzoxcreation2555 Год назад +1

      @@codestorywithMIK thanx ✌ .. New subscriber🙂..

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      Tysm ❤️

  • @TheBaljitSingh
    @TheBaljitSingh 7 месяцев назад

    can anyone tell me why my code give TLE?? i am using a map
    bool allZero(map mp, string &pat){
    for(int i=0; i

  • @abhishek_singh512
    @abhishek_singh512 Год назад

    Java code bhi de diya kijiye sir 🙏🙏🙏🙏

  • @harshnamdeo613
    @harshnamdeo613 7 месяцев назад

    can someone give code in javascript

  • @PakIslam2012
    @PakIslam2012 Год назад

    Wouldnt the time complexity of this also be O(m*n)?

    • @SATYAMGOVINDRAO-po6mt
      @SATYAMGOVINDRAO-po6mt 7 месяцев назад

      I think 26*m(size of bigger string) ,26 because counter Length is constant

  • @jatin9987
    @jatin9987 4 месяца назад

    anyone plese can you give same code in JAVA 🙏🙏

    • @codestorywithMIK
      @codestorywithMIK  4 месяца назад +1

      JAVA code added in the github link in the description also
      class Solution {
      private boolean allZero(int[] count) {
      for (int num : count) {
      if (num != 0) {
      return false;
      }
      }
      return true;
      }
      int search(String pat, String txt) {
      int k = pat.length();
      int[] count = new int[26];
      Arrays.fill(count, 0);
      for (char ch : pat.toCharArray()) {
      count[ch - 'a']++;
      }
      int i = 0, j = 0;
      int n = txt.length();
      int result = 0;
      while (j < n) {
      int idx = txt.charAt(j) - 'a';
      count[idx]--;
      if (j - i + 1 == k) {
      if (allZero(count)) {
      result++;
      }
      count[txt.charAt(i) - 'a']++;
      i++;
      }
      j++;
      }
      return result;
      }
      }

  • @invincible_5956
    @invincible_5956 7 месяцев назад

    can any please check my code it giving 0 as answer always
    int search(string pat, string txt) {
    int p[26]={0};int t[26]={0};
    const char *s = pat.c_str(); int len=0;
    while (*s)
    {
    p[*s-'a']++;
    s++; len++;
    }
    int count=0; int flag=1;
    const char *x = txt.c_str(); int lent=0; const char *first = txt.c_str();
    while(*x)
    {
    t[*x-'a']++;

    if(lent>=len) { flag=1;
    for(int row=0;row