L10. Count number of Nice subarrays | 2 Pointers and Sliding Window Playlist

Поделиться
HTML-код
  • Опубликовано: 25 мар 2024
  • Notes/Codes/Problem links under step 10 of A2Z DSA Course: takeuforward.org/strivers-a2z...
    Entire playlist: • Two Pointer and Slidin...
    Follow us on our other social media handles: linktr.ee/takeuforward

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

  • @messiisthebest
    @messiisthebest 3 месяца назад +9

    i have been watching your video since 2 week, now I solved this without watching your video, whole credit goes to you

  • @vrandakansal5940
    @vrandakansal5940 3 месяца назад +7

    The way u change this problem to the previous question.. amazing. Thanks a lot😀💯

  • @Cool96267
    @Cool96267 Месяц назад +2

    Thankyou so much Striver for all you efforts throughout in delivering us so much valuable content. Any student / working professional can now be able to transition their career without paying money for courses.
    Would also like your insights on the point :
    While preparing for interviews most of the aspirants are going through the videos solely and solving the question after completely watching the video. And also are feeling lazy trying to solve the question on our own. What is the best way to complete any topic without being lazy and how should an aspirant approach any topic/playlist?

  • @user-yz9mk2jf1j
    @user-yz9mk2jf1j 3 месяца назад

    this is the best channel

  • @tgayush1424
    @tgayush1424 2 месяца назад +14

    add this to your title - 1248. leetcode question number , such that it will come on top search .

  • @Madhu-tl8kq
    @Madhu-tl8kq 3 месяца назад

    There is a type the inner while loop should check while(map.size() > k ) then only we need to reduce the frequency

  • @sriramphysics5853
    @sriramphysics5853 3 месяца назад

    very good striver

  • @divyanshutripathi5305
    @divyanshutripathi5305 3 дня назад

    thanks for this wonderful video

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

    Understood ❤

  • @satraprathore5349
    @satraprathore5349 2 месяца назад

    Mindblown

  • @aaranyaksantra9933
    @aaranyaksantra9933 Месяц назад

    nice explaination

  • @cenacr007
    @cenacr007 Месяц назад +4

    Do add Leetcode question number as well in video title for better search results.

  • @ramakrishnakcr4417
    @ramakrishnakcr4417 3 месяца назад

    understood

  • @user-lt2ie8ys3n
    @user-lt2ie8ys3n 28 дней назад

    Striver on a different level

  • @Deepak_chakravarti
    @Deepak_chakravarti 25 дней назад +1

    Finally mil gya 🥲

  • @nakulchauhan6713
    @nakulchauhan6713 2 месяца назад +1

    there is no need for modifying array to 0 and 1.
    We can just use sliding window with concept of finding subarrays with odd numbers less the k - subarrays with odd numbers less then k-1

    • @lakshsinghania
      @lakshsinghania 2 месяца назад

      yeah tru dat, he just did so that to convert into the prev qs

  • @karamveeryadav8824
    @karamveeryadav8824 17 дней назад

    striver we want strings and stack playlist

  • @ahappyperson6530
    @ahappyperson6530 23 дня назад

    here we are using O(4N) TC at worst case but there's a better approach to solve it with [TC = O(N) & SC = O(1)]

  • @RajatMishra-ks7ns
    @RajatMishra-ks7ns Месяц назад

    solutions:
    class Solution {
    public:
    int solve(vector& nums, int k){
    if(k

  • @GeetainSaar
    @GeetainSaar 24 дня назад

  • @eaglestargamer4813
    @eaglestargamer4813 15 дней назад

    class Solution {
    public int numberOfSubarrays(int[] nums, int k) {
    int left = 0;
    int right = 0;
    int count = 0;
    Queue q = new LinkedList();
    int n = nums.length;
    while(right < n)
    {
    if(nums[right] % 2 == 1)
    {
    q.add(right);
    }
    while(left < right && q.size() > k)
    {
    left = q.poll() + 1;
    }
    if(q.size() == k)
    {
    count += (q.peek() - left) + 1;
    }
    right++;
    }
    return count;
    }
    }

    • @SurajSingh-mf3vz
      @SurajSingh-mf3vz 11 дней назад

      Dude, we think so alike :)
      I didn't see anyone utilizing queues in this problem
      class Solution:
      def numberOfSubarrays(self, nums: List[int], k: int) -> int:
      odd_queue = deque()
      j, count = 0, 0
      for i, num in enumerate(nums):
      if num % 2 == 1:
      odd_queue.append(i)
      if len(odd_queue) > k:
      j = odd_queue.popleft() + 1
      if len(odd_queue) == k:
      count += 1 + odd_queue[0] - j
      return count

  • @indian3412
    @indian3412 24 дня назад +1

    but it wont work for the test case:
    [2,2,2,1,2,2,1,2,2,2] k=2
    Because at l=0 r=0, r will reach upto last index because sum

    • @naRRATE1019
      @naRRATE1019 15 дней назад +1

      It is not like that, instead we are counting number of possible substring at each index it is going, (count += (right-left+1)), for l=0, r=0 count = 1, l=0, r=1, count += 1-0+1 => count = 3, count = 6, ..... similarly it will reach the end(as k

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

    1248. Leetcode problem

  • @lol_xoxo78
    @lol_xoxo78 24 дня назад

    3:15 AM at night 🌃

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 3 месяца назад +1

    public int numberOfSubarrays(int[]nums,int k){
    int n=nums.length;
    int[]cnt=new int[n+1];
    cnt[0]=1;
    int sum=0,ans=0;
    for(int num:nums){
    sum+=num%2;
    if(sum>=k)
    ans+=cnt[sum-k];
    cnt[sum]++;
    }
    return ans;
    }
    🎉❤

  • @ManishKumar-dk8hl
    @ManishKumar-dk8hl 3 месяца назад +3

    class Solution {
    public int helpMe(int[] nums,int goal){
    int l=0;
    int r=0;
    int sum=0;
    int cnt=0;
    if(goal

  • @pranjalkumar8909
    @pranjalkumar8909 3 месяца назад

    I think it will fail for a=[2,4,6] and k=2

    • @es_amit
      @es_amit 2 месяца назад

      nhi bro maine khud solve kiya toh fail nhi hua bs func me
      if(k

    • @Harsh-jc2bz
      @Harsh-jc2bz Месяц назад

      @@es_amit tum kitnai saal k ho?

    • @es_amit
      @es_amit Месяц назад

      @@Harsh-jc2bz 20 kyu kuch kaam hai?