Number of Subsequences That Satisfy the Given Sum Condition | AMAZON | Leetcode - 1498 | Live Coding

Поделиться
HTML-код
  • Опубликовано: 5 окт 2024

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

  • @ashutoshpandey1639
    @ashutoshpandey1639 Год назад +9

    The best thing about your videos is if I saw any other solution video I feel regret, but your explanation gave another level understanding and satisfaction that maine ye problem Sikh Li ab kisi ko samjha skta hu❤

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

    Hi guys,
    Make sure you don't skip even a single second of this video. Especially the Story Points part 21:12 . The dots will connect and the solution will hit you.
    I hope we all learned something new today from this problem. ❤❤❤

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

      bro applause to your courage that you honestly tell that power factor scene, really its works as a motivation for a budding coder .❤

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

      Thank you so much shivansh ❤️❤️❤️

  • @whothefisyash
    @whothefisyash 26 дней назад +1

    wow so smooth

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

    One of the best teachers on this platform.🤩🤩

  • @vetlakvsatyanarayana746
    @vetlakvsatyanarayana746 Год назад +6

    can you explain subsets, subsequences, subarrays, substrings and all in one video with an example in detail?

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

    The pre-computational part was nuts.

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

    I am speechless at how beautifully you explained the problem. I've watched other RUclips videos on the same problem, but I couldn't grasp the intuition behind it. They jumped straight into the problem without giving any explanation, so I struggled to write the code on my own. However, after watching your video, I finally understood the right intuition and just how simple the code is (even without watching your story points). When you said, "code toh aap likh hi loge," I was skeptical, but later I realized the significance of that statement. Thank you for making this video. You've earned yourself a new subscriber, and I will definitely recommend your video to anyone learning DSA. Hats off to you! 🫡❤

  • @shreyaesha001
    @shreyaesha001 Год назад +4

    can't thank you enough!

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

    You are amazing , one request is please make up solving of leetcode contests🙏🙏

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

      Thank you so much ❤️❤️❤️
      And sure contest i will try soon

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

    ur best

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

    THanks for the detailed solution .

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

    appreciate your detailed solution!

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

    Amazing Explanation

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

    Amazing Explanation, thank you 👍👍

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

    Another solution, we can use binary exponentiation to get rid of the power vector.... but each and everytime we've to call it to calculate the power(2, something) which we'll take LESS THAN SQRT(N) tc
    but your solution is the better one if we look at the TC....
    and this one is better if we go for SPACE OPTIMISATION
    # CODE CPP
    class Solution {
    const int M = 1e9 + 7;
    int powerOf2(long long x, int n) {
    int power = 1;
    while (n) {
    if (n & 1)
    power = ( (x % M) * (power % M) ) % M;
    n = n >> 1;
    x = ( (x % M) * 1ll * (x % M) ) % M;
    }
    return power;
    }
    public:
    int numSubseq(vector& nums, int target) {

    int n = nums.size();

    sort(nums.begin(), nums.end());

    long long int ans = 0;

    int low = 0;
    int high = nums.size() - 1;

    while (low

  • @youKnowMe4real
    @youKnowMe4real 8 месяцев назад

    best

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

    Thank you Sir.

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

    if we use pow(2,n)%M , then modulo doesn't help us. because, pow is calculating the value first, then it will be modulo. but when pow calculates the value, it goes past the range of integer. And when it already goes past the range of integer, the modulo has nothing to do. So we use precalculation of power. And during that precalculation, we always do modulo in each element. So the value can't go past the range of integer. another option was to use binpow. but I like this type of precalculation. This comment is not for Mazhar vai, it's for noobs like me. Thanks mazhar vai.

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

      What a summary. Thank you so so much ❤️❤️❤️

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

    can we connect on linkedIn ?
    and solution video is simply awesome.

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

      Sure thing.
      LinkedIn - www.linkedin.com/in/mazhar-imam-khan-95a34ab3
      LinkedIn codestorywithMIK Page - www.linkedin.com/groups/12559380
      Instagram : instagram.com/codestorywithmik/
      Facebook : facebook.com/people/codestorywithmik/100090524295846/

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

    can we use left shift operator to calculate power?

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

    Best mann best!

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

    well explained!!!

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

    In 2,3,3,4,6,7, when L move from value 3(L=0) to 3(L=1), don’t we get overlapping sets? Both can have 3,4,6,7. Is above statement correct?

  • @gui-codes
    @gui-codes 6 месяцев назад

    great .

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

    This extra thing of using modulo , seems very confusing to me , if you could tell more about how modulo helps in large solution , it will be very helpful

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

      Sure Supriya. Let me try to make a video soon on this and explain the purpose behind modulo

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

    Hey bro thanks alot, spent alot of time trying to understand why it was 2^(n-1) and not (2^n)-1, dusre vids bhi dekhe bt it wasn't explained clearly at all, ab ajke samaj aya we are fixing the min value thats why, thanks bro btw can u post theae vids abit earlier please

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

      Thank you so much ❤️❤️
      And yes i will start posting earlier. Actually the delay is because of my throat infection treatment being done. I have recovered now and will be back to early videos
      Thank you for watching ❤️❤️

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

      @@codestorywithMIK cool bro awesome, btw a thing i noticed as i have started spending more time in dsa is that some days my brain works great n some days it doesn't work at all and i cant solve even simple stuff, is there any fix to this or is it kind of burnout?

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

      That’s totally totally fine. It happens.
      I always suggest to give oneself a break to relax and enjoy.
      May be Sundays , keep it free to relax and enjoy a little. And in other days, work harder like no one can ever beat you 💪💪💪

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

      @@codestorywithMIK thats the josh🔥but i have so much left to complete that i feel bad for taking time off 🙂

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

    Brute Force approach using include/exclude pattern
    const isValid = (temp: number[], target: number) => {
    const min = Math.min(...temp);
    const max = Math.max(...temp);
    return max + min {
    const dfs = (i: number, temp: number[]): number => {
    if (i >= array.length) {
    if (isValid(temp, target)) {
    return 1;
    } else {
    return 0;
    }
    } else {
    temp.push(array[i]);
    const take = dfs(i + 1, temp);
    temp.pop();
    const doNotTake = dfs(i + 1, temp);
    return take + doNotTake;
    }
    };
    return dfs(0, []);
    };

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

      @codestorywithMIK, can we solve this problem with DP?

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

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

    we can also use binaryExponentiation for that pow() case

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

      Thanks for sharing ❤️❤️
      Would you please share any good resource from where I can read the documentation for this method also

    • @006_pratiksonthaliya9
      @006_pratiksonthaliya9 Год назад

      ​@@codestorywithMIK ruclips.net/video/J63JPxqmyzg/видео.html

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

      have you tried to use binaryExponentiation i feel that we can't use it as it will just increase the complexity.... and Math.pow is O(1) function and outputs the same thing that binaryExponentation will give... If you were able to make it work?? can you send me the code... because issue was that pow was too big....

    • @006_pratiksonthaliya9
      @006_pratiksonthaliya9 Год назад +1

      @@architchanana7866 yes it will increase the time complexity by factor of O(logn).... So no need to go for that
      Stick with the simple approach

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

      @@architchanana7866 It Worked for me
      Here's the code:
      class Solution {
      private:
      const int M = 1e9+7;
      int binExp(int a, int b)
      {
      int ans = 1;
      while(b)
      {
      if(b&1)
      {
      ans = (ans * 1LL * a) % M;
      }
      a = (a * 1LL * a) % M;
      b >>= 1;
      }
      return ans;
      }
      public:
      int numSubseq(vector& nums, int target) {
      sort(begin(nums), end(nums));
      int n = nums.size();
      int s = 0, e = n-1;
      int ans = 0;
      while(s target)
      {
      e--;
      }
      else
      {
      ans = (ans + binExp(2, e-s)) % M;
      s++;
      }
      }
      return ans;
      }
      };

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

    As always ❤

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

    Can we solve this problem using binary search?

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

    Hi MIK ❤ Aaj ka Leetcode challange question daalne vale ho?

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

      Hi Hiren. Yes it will come today.
      Just need some time. Little occupied in medications and hospitality

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

      @@codestorywithMIK 😊❣️Get well soon MIK 💕

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

    I used the same code without modulo and with pow() function , but i got wrong answer instead of runtime , below is the code , It is very helpful if you able to told where my code went wrong ??
    int numSubseq(vector& nums, int target) {
    sort(nums.begin(), nums.end());
    long long int out = 0;
    int i=0,j=nums.size()-1;
    while(i

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

    Java Code:
    class Solution {
    public int numSubseq(int[] nums, int target)
    {
    Arrays.sort(nums);
    int l=0;
    int r=nums.length - 1;
    int mod=1000000007;
    int power[]=new int[nums.length];
    power[0]=1;
    for(int i=1;i

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

    Aur bhai, gala thik?

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

      Today was my last doctors appointment.
      It’s almost better now.

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

      @@codestorywithMIK precompute kyu krna, binpow use kr lijiye 😅