L9. Binary Subarrays With Sum | 2 Pointers and Sliding Window Playlist

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ธ.ค. 2024

ความคิดเห็น • 115

  • @amansingh-hb9ko
    @amansingh-hb9ko 8 หลายเดือนก่อน +40

    just a small correction in first while condition r should less only size not equal to while(r

    • @Funzee
      @Funzee 6 หลายเดือนก่อน

      do u know where is the article of this code

    • @moonlight-td8ed
      @moonlight-td8ed 5 หลายเดือนก่อน

      @@Funzee there isnt one i guess

  • @rushidesai2836
    @rushidesai2836 3 หลายเดือนก่อน +24

    Never in my dreams would have thought of such an ingenious solution. Wow.

  • @Demon01Editz
    @Demon01Editz 5 หลายเดือนก่อน +22

    Code :
    class Solution {
    public:
    int lessequaltok(vector& nums,int goal){
    if(goal < 0)
    return 0;
    int l = 0;
    int r = 0;
    int ans = 0;
    int n = nums.size();
    int sum = 0;
    while(r < n){
    sum += nums[r];
    while(sum > goal){
    sum -= nums[l];
    l++;
    }
    ans += (r-l+1);
    r++;
    }
    return ans;

    }
    int numSubarraysWithSum(vector& nums, int goal) {
    return lessequaltok(nums,goal)-lessequaltok(nums,goal-1);
    }
    };

  • @Asmir-p1z
    @Asmir-p1z 8 หลายเดือนก่อน +32

    It becomes hard problem when we try to solve using sliding window but how easily Striver was able to explain it is just Awesome and much appreciated❤❤❤

  • @SuvradipDasPhotographyOfficial
    @SuvradipDasPhotographyOfficial 5 หลายเดือนก่อน +30

    This is an Excellent Question, truly amazing tutorial striver. Kudos to you bro. Striver only heap and stack queues are left, hoping to get those series soon. Take care of your health bro. The entire DSA community will forever be indebted to you.

  • @dipanshuraj7868
    @dipanshuraj7868 หลายเดือนก่อน +2

    I was stunned when I saw this approach and realised this type of content was not available in the premium videos.

  • @AkhileshPadiyar
    @AkhileshPadiyar 3 หลายเดือนก่อน +6

    The most optimal solution is a very great concept and will help you solve many problems in sliding window, even the hard ones......

  • @MotivationMantra2
    @MotivationMantra2 2 หลายเดือนก่อน +19

    if anyone is unable to understand why fun(nums,goal) - fun(nums,goal-1) works here? What's the math here? I am unable to understand this basic maths behind it, please can anyone explain me the maths behind this?
    Answer : (if you read below example definetly u can understand)
    Example: Counting people by weight categories
    Imagine you have a group of people, and each person has a specific weight. You want to know how many people weigh exactly 70 kg.
    Step 1: Count all people weighing less than or equal to 70 kg
    This will include people who weigh:
    Less than 70 kg (like 60 kg, 50 kg, etc.)
    Exactly 70 kg
    Let’s say we count all the people who weigh 70 kg or less:
    There are 25 people who weigh 70 kg or less.
    We can represent this as fun(weights, goal=70) = 25.
    Step 2: Count all people weighing less than or equal to 69 kg
    Now, let’s count all the people who weigh 69 kg or less. These are people who weigh:
    Less than 70 kg (like 69 kg, 60 kg, 50 kg, etc.)
    But not those who weigh exactly 70 kg.
    Let’s say there are 18 people who weigh 69 kg or less.
    We can represent this as fun(weights, goal=69) = 18.
    Step 3: Subtract the two results
    To find out how many people weigh exactly 70 kg, we subtract:
    fun(weights, goal=70) (people weighing 70 kg or less) = 25
    fun(weights, goal=69) (people weighing 69 kg or less) = 18
    The number of people who weigh exactly 70 kg is:
    25 - 18 = 7 people.
    General Formula:
    fun(weights, goal) counts how many people have a weight less than or equal to the goal (here, 70 kg).
    fun(weights, goal-1) counts how many people have a weight less than or equal to goal - 1 (here, 69 kg).
    By subtracting the two, you get the number of people who weigh exactly the goal weight.
    Why it works:
    This technique isolates the exact count of people (or items) at the goal value by subtracting the number of items below the goal from the number of items less than or equal to the goal. It's easier than directly counting "exact" matches in some problems, which is why this approach is useful.

    • @CodeWithCuriosity
      @CodeWithCuriosity หลายเดือนก่อน +2

      take it like this , (sum

    • @VIJAYSHARMA-dh6vo
      @VIJAYSHARMA-dh6vo หลายเดือนก่อน

      beautifully explained bro thanks had a confusion intially

    • @ketan_sahu
      @ketan_sahu หลายเดือนก่อน

      Thanks for the explanation!!!

    • @Unkown3457-c6p
      @Unkown3457-c6p หลายเดือนก่อน

      Thanks bro

    • @killer-oo2rs
      @killer-oo2rs 23 วันที่ผ่านมา

      its basically set theory, you have something like: S

  • @mayurbhat9479
    @mayurbhat9479 5 หลายเดือนก่อน +2

    Understood. While solving this with the sliding window, I got the wrong answer and wondered why. Thanks for the explanation.

  • @RohitKumar-hn6wj
    @RohitKumar-hn6wj 8 หลายเดือนก่อน +7

    best series on sliding windows. thanks a lot.

  • @abirsaha297
    @abirsaha297 5 หลายเดือนก่อน +1

    the solution is amazing ...opened up my mind..superb explanation but i wonder striver did it so easily when will i be able to build such intuition ... i got great confidence throughout the playlist but the way sir brought up the solution amazed me but also gave lot of questions as to when will i be able to think like this

    • @jritzeku
      @jritzeku 5 หลายเดือนก่อน +2

      Honestly for subarray sum problems having negative values or 0s , prefixSum is the way to go. It's slightly less performant but more intuitive. I tried learning the optmized approach several times but its too clever and unlikely to come up with during interview given that we have so many other data structures, algs patterns to worry about already lol.
      Problems w/ prefixSum: subarray sum equals k, binary sum equals k , nice subarrays(SAME logic as binary sum w/ slight change).

  • @LogicArena01
    @LogicArena01 5 หลายเดือนก่อน

    Amazing ❤ love your teaching style and love how you teach us how to think from the scratch ❤

  • @anujvijaypatilb22ee010
    @anujvijaypatilb22ee010 5 หลายเดือนก่อน +2

    class Solution {
    public:
    int count(vector& nums, int goal) {
    int left = 0;
    int right = 0;
    int sum = 0;
    int count = 0;
    // if()
    while (right < nums.size()) {
    sum += nums[right];
    while (sum > goal && left

  • @huungryyyy
    @huungryyyy 5 หลายเดือนก่อน +1

    Here is the solution
    class Solution {
    public:
    int Calculate(vector& nums, int target) {
    int front=0;
    int end=0;
    int count=0;
    int sum =0;
    if(target

  • @CS090Srikanth
    @CS090Srikanth 2 หลายเดือนก่อน

    Can we use the second approach to solve number of subarrays with sum k where the array consists of only positive integers?
    No. Of subaarys with sum

  • @techyguyaditya
    @techyguyaditya 8 หลายเดือนก่อน +7

    At 16:15 I am getting problem here. Why are we considering all the count of r-l+1 when we only get 1 count instead of 4 in the case of 1001? The same problem got reflected in leetcode too, getting wrong answer in test cases.
    Solution: watch lecture 11 to understand in detail. The code is correct if goal is

    • @himage6540
      @himage6540 2 หลายเดือนก่อน

      u should've watched the video till the last

  • @aravindvinjamuri1873
    @aravindvinjamuri1873 3 หลายเดือนก่อน +3

    i can stop the video only after listening to that music at the end😁😁

  • @purushottam108
    @purushottam108 5 หลายเดือนก่อน

    class Solution {
    public:
    int fun(vector& arr, int goal){
    if(goal < 0 ) return 0;
    int l = 0, r = 0 , cnt = 0;
    int sum = 0;
    while(r < arr.size()){
    sum += arr[r];
    while(sum > goal){
    sum -= arr[l];
    l++;
    }
    cnt += r - l + 1;
    r++;
    }
    return cnt;
    }
    int numSubarraysWithSum(vector& nums, int goal) {
    return fun(nums,goal) - fun(nums,goal - 1);
    }
    };

  • @shikharchoudhary7639
    @shikharchoudhary7639 3 หลายเดือนก่อน

    Thanks striver the solution is cleared.

  • @sandipanadhikary5546
    @sandipanadhikary5546 4 หลายเดือนก่อน

    Damn this was really something 🔥🔥🔥 the day i start thinking like striver cracking google ll be a piece of cake😅

  • @PratapSingh-yg8tc
    @PratapSingh-yg8tc 7 หลายเดือนก่อน +17

    It becomes hard problem when we try to solve using sliding window but for you everything is so easy ,how we can think like you

  • @iamstudying389
    @iamstudying389 หลายเดือนก่อน

    wow this made me say wow and when that goal-1 thing again wow

  • @hashcodez757
    @hashcodez757 3 หลายเดือนก่อน

    #BHAIYA

  • @yashhokte1020
    @yashhokte1020 3 หลายเดือนก่อน +5

    I am unable to understand why fun(nums,goal) - fun(nums,goal-1) works here? What's the math here? I am unable to understand this basic maths behind it, please can anyone explain me the maths behind this?

    • @SANDEEPDHAVALA
      @SANDEEPDHAVALA 2 หลายเดือนก่อน

      please watch A - B in this video ( th-cam.com/users/shorts3uaVqX5qClg?si=c2yO4X4gQwXrqm3u )
      continue reading after watching the video.
      draw the venn diagram of A-B on paper and refer to it while reading this comment for better understanding.
      lets assume you need people who have 2 rupees that is ( fun(nums,goal) here we are finding people who

    • @manikanta2000
      @manikanta2000 2 หลายเดือนก่อน +7

      if you have 5 $1 candy and 10 $2 candy. Number of candies

  • @stith_pragya
    @stith_pragya 7 หลายเดือนก่อน +1

    UNDERSTOOD...Thank You So Much for this wonderful video........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @ManishKumar-dk8hl
    @ManishKumar-dk8hl 8 หลายเดือนก่อน +12

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

    • @chakrabarti9634
      @chakrabarti9634 8 หลายเดือนก่อน +1

      Why goal - goal-1 please help😊

    • @Rahul_Mongia
      @Rahul_Mongia 6 หลายเดือนก่อน +1

      @@chakrabarti9634 Dekh bhai example se samjthe hai
      let goal=2
      Calculate helpMe(nums, goal)
      This function will count all subarrays with sums less than or equal to 2.
      Subarrays with sum 0: []
      Subarrays with sum 1: [1], [0], [1], [0], [1], [1,0], [0,1], [1], [1,0]
      Subarrays with sum 2: [1,0,1], [0,1,0], [1,0,1], [1,0], [0,1,0,1], [1,0,1], [1,0,1]
      Calculate helpMe(nums, goal - 1)
      This function will count all subarrays with sums less than or equal to 1.
      Subarrays with sum 0: []
      Subarrays with sum 1: [1], [0], [1], [0], [1], [1,0], [0,1], [1], [1,0]
      Find the Exact Count
      The number of subarrays with sum exactly 2 is helpMe(nums, 2) - helpMe(nums, 1).
      Aya samjh....

    • @jitinroy2246
      @jitinroy2246 หลายเดือนก่อน

      @@chakrabarti9634 to find out the exact number of counts equal to sum k.

  • @kingkohli7175
    @kingkohli7175 4 หลายเดือนก่อน

    INSANE BROTHER♥♥

  • @augustinradjou3909
    @augustinradjou3909 8 หลายเดือนก่อน

    Long time I was waiting to get these types of problems...good one...

  • @huungryyyy
    @huungryyyy 5 หลายเดือนก่อน

    thanku striver bhaiya🙂🙂

  • @ashj1165
    @ashj1165 หลายเดือนก่อน

    superb!!!
    understood!!!

  • @aayushgakhar3525
    @aayushgakhar3525 4 หลายเดือนก่อน +1

    i tried this approach on number of distinct char in string ==k and it passes only 433/1050 test case then gives tle

  • @atg878
    @atg878 5 หลายเดือนก่อน +1

    thanks a lot ❤❤

  • @harshdhochak8361
    @harshdhochak8361 5 หลายเดือนก่อน

    here is the c++ code;
    class Solution {
    public:
    // it will calculate for

  • @shashankvashishtha4454
    @shashankvashishtha4454 4 หลายเดือนก่อน

    understood

  • @shrutiagarwal-ux1qz
    @shrutiagarwal-ux1qz 7 หลายเดือนก่อน +5

    how did you get the intution of using this approach

  • @shashanknakashe3339
    @shashanknakashe3339 5 หลายเดือนก่อน +4

    this is the solution that raj bhaiya told us do at last goal-goal-1;
    class Solution {
    public:
    int numSubarraysWithSum(vector& nums, int goal) {
    int l=0;
    int r= 0;
    int count =0;
    int sum = 0 ;

    while(r < nums.size()){
    sum = sum+ nums[r];
    while(sum>goal){
    sum = sum -nums[l];
    l++;
    }
    if(sum

  • @rethickpavan4264
    @rethickpavan4264 5 หลายเดือนก่อน

    Brilliant 🤯

  • @evilgame6197
    @evilgame6197 6 หลายเดือนก่อน +7

    in my entire lifetime I will never be able to come to this solution by my own

    • @jritzeku
      @jritzeku 5 หลายเดือนก่อน +6

      And thats completely fine. Consider them as like Mathematical formulas. Recall that without having learned formulas, it would be nearly impossible to solve even simple math problems. Unfortunately these patterns are not covered in traditional CS curriculums where we just learn data structures, and common algorithms like traversals ,insertions ,deletions. Also another common pattern/strategy is to use the prefixSum solution.
      You shouldn't feel like you have to come up with these patterns on your own...just like math formulas lol.

    • @devanshsingh2
      @devanshsingh2 5 หลายเดือนก่อน +3

      @@jritzeku Thanks for the motivation dude 🥲😊

  • @DeveshSoni-u6s
    @DeveshSoni-u6s 7 หลายเดือนก่อน

    I never thought of a solution this way. Awesome

  • @Zomb-zj4ip
    @Zomb-zj4ip 5 หลายเดือนก่อน

    understood, thank you

  • @hareshnayak7302
    @hareshnayak7302 7 หลายเดือนก่อน

    Understood,Thanks striver for this amazing video.

  • @SaurabhKumar-tq8zn
    @SaurabhKumar-tq8zn 5 หลายเดือนก่อน +1

    why you added r-l+1 , why not +1

  • @PiyushKumar-xe1ng
    @PiyushKumar-xe1ng 3 หลายเดือนก่อน +2

    whose brain could have thought like that 🤯

  • @oyeshxrme
    @oyeshxrme 4 หลายเดือนก่อน

    thanks bhaiya

  • @--Sreekarsai
    @--Sreekarsai 8 หลายเดือนก่อน +8

    Why there is no code

  • @yaxprajapati115
    @yaxprajapati115 5 หลายเดือนก่อน

    How will we identify if the question is of this type ? or normal sliding window?

    • @KartikeyTT
      @KartikeyTT 5 หลายเดือนก่อน

      this type -> we have to count the no of subarrays
      normal sliding windows -> we have to find longest length subarray
      watch video 1 of the playlist and refer type 2 and type 3 problems in the vid

  • @ashishpradhan6250
    @ashishpradhan6250 5 หลายเดือนก่อน

    superb

  • @SibiRanganathL
    @SibiRanganathL 3 หลายเดือนก่อน +1

    Understood: Big brain time

  • @rishabsharma5307
    @rishabsharma5307 5 หลายเดือนก่อน

    Solution using the same method as L7
    TC: O(2*n)
    SC: O(n) in worst case
    ```
    int numSubarraysWithSum(vector& nums, int goal) {
    int i, j, sum, count, n = nums.size();
    queue mq;
    i = j = sum = count = 0;
    int k = goal > 0 ? 1 : 0;
    while(j < n)
    {
    sum += nums[j];
    if(nums[j] == k)
    mq.push(j);
    while(sum > goal)
    {
    sum -= nums[i];
    if(nums[i] == 1)
    mq.pop();
    ++i;
    }
    if(sum == goal)
    {
    if(goal > 0)
    count += mq.front() - i + 1;
    else
    count += j-i+1;
    }
    ++j;
    }
    return count;
    }
    ```

  • @abhaykumarsingh3884
    @abhaykumarsingh3884 3 หลายเดือนก่อน

    Optimal wala to bahut hi jada intuitive hai..
    kab pata chalega ki aise bhi solve kar skte hai??

  • @SitaRam-m1i
    @SitaRam-m1i หลายเดือนก่อน

    Understood

  • @naturesrevolution
    @naturesrevolution 3 หลายเดือนก่อน +1

    how it will run for two times ? I can't get it ☹

    • @himage6540
      @himage6540 2 หลายเดือนก่อน

      because you'll call it two times

  • @vidhiagarwal9370
    @vidhiagarwal9370 4 หลายเดือนก่อน

    why did we not solve using prefixSum then?

    • @tusharyadav5874
      @tusharyadav5874 4 หลายเดือนก่อน

      It can be solved but we want to reduce the space complexity from O(N) which was used in the prefix sum to O(1) .

  • @subhadrosamaddar6336
    @subhadrosamaddar6336 6 หลายเดือนก่อน

    incredible

  • @ashimaanand992
    @ashimaanand992 8 หลายเดือนก่อน +3

    Shouldn't the complexity be O(n^2) and not O(2*n)

  • @torishi82
    @torishi82 6 หลายเดือนก่อน

    Awesome bhai. Understood.

  • @pranavmisra5870
    @pranavmisra5870 6 หลายเดือนก่อน

    amazing

  • @satyareddy8671
    @satyareddy8671 6 หลายเดือนก่อน

    super anna super logic what is vision what a thought

  • @HimanshuGupta-yv4lf
    @HimanshuGupta-yv4lf 5 หลายเดือนก่อน

    Thanks for the tutorial but, this gives result for

  • @thaman701
    @thaman701 8 หลายเดือนก่อน +2

    Striver be like ----goli ki speed se videos upload kr dunga.😂❤

  • @PawanKumar-hq6dy
    @PawanKumar-hq6dy หลายเดือนก่อน

    class Solution {
    public int numSubarraysWithSum(int[] nums, int goal) {
    int i=0, j=0, subArrayCount =0, sum =0;
    int tempI =0,tempSum =0;
    while(jgoal){
    sum = sum - nums[i];
    i++;
    tempI = i;
    }
    tempSum = sum;
    while(tempSum==goal && tempI

  • @shubhtandon8315
    @shubhtandon8315 5 หลายเดือนก่อน

    Just Wowww!

  • @nikhilverma2008
    @nikhilverma2008 2 หลายเดือนก่อน +1

    I will not be able to solve it in one go .

  • @angeldeveloper
    @angeldeveloper 8 หลายเดือนก่อน

    Thanks a ton ❤

  • @SANSKARSAHU-j3n
    @SANSKARSAHU-j3n 4 หลายเดือนก่อน

    Why are we calling it for 2 time ?

  • @codeman3828
    @codeman3828 7 หลายเดือนก่อน

    Understood. Thanks!

  • @siddhantksingh2514
    @siddhantksingh2514 6 หลายเดือนก่อน

    r less than n not r less than equal to

  • @harshitshiva1
    @harshitshiva1 3 หลายเดือนก่อน

    add the code bro pls
    and artical also pls

  • @heetpatel6602
    @heetpatel6602 8 หลายเดือนก่อน

    striver thanks!

  • @abhaysinhgaikwad
    @abhaysinhgaikwad 8 หลายเดือนก่อน +2

    anyone fix this
    class Solution {
    public int numSubarraysWithSum(int[] arr, int k) {
    int n = arr.length, count = 0, sum = 0, r= 0, l = 0;

    while(r < n){
    sum += arr[r];
    while(sum > k){
    sum -= arr[l];
    l++;
    }
    if(sum == k){
    count += r - l + 1;
    }
    r++;
    }
    return count;
    }
    }

    • @tejaswaniguttula5961
      @tejaswaniguttula5961 8 หลายเดือนก่อน +1

      @abhaysinhgaikwad
      Hi brother,
      class Solution {
      public int func(int[] arr, int k) {
      int sum = 0, l = 0, r = 0, count = 0;
      if (k < 0) return 0;
      while (r < arr.length) {
      sum += arr[r];
      while (sum > k) {
      sum -= arr[l];
      l++;
      }
      if (sum

  • @ajithshetty1684
    @ajithshetty1684 6 หลายเดือนก่อน

    But how to return this value in function in leetcode, wont it be recursive?

    • @ajithshetty1684
      @ajithshetty1684 6 หลายเดือนก่อน

      class Solution:
      def numSubarraysWithSum(self, nums: List[int], goal: int) -> int:
      def fun1(nums,goal):
      if goal < 0:
      return 0
      l = 0
      r = 0
      sum = 0
      cnt = 0
      while r goal:
      sum = sum-nums[l]
      l=l+1
      cnt+=r-l+1
      r=r+1
      return cnt
      return fun1(nums,goal)-fun1(nums,goal-1)

  • @AyushEditz-hs6pf
    @AyushEditz-hs6pf 3 หลายเดือนก่อน

    this video is a little confusing. Watch this again after some time and trust me you will understand much better.

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 8 หลายเดือนก่อน

    public int numSubarraysWithSum(int[]nums,int goal){
    int prefixZero=0,sum=0,ans=0,i=0,j=0;
    while(j

  • @KartikeyTT
    @KartikeyTT 8 หลายเดือนก่อน

    it should be r

    • @manikanta6183
      @manikanta6183 8 หลายเดือนก่อน

      Since the array is 0-Indexed.
      Indexing -> 0,1,2,3
      for example nums = {6,4,3,7}
      nums.size() would be 4, So ultimately we would be accessing the index which is out of bounds

    • @KartikeyTT
      @KartikeyTT 8 หลายเดือนก่อน

      @@manikanta6183 yeah thats what i meant

    • @manikanta6183
      @manikanta6183 8 หลายเดือนก่อน

      ​@@KartikeyTTMy bad, I thought you were asking the question 😂

    • @KartikeyTT
      @KartikeyTT 8 หลายเดือนก่อน

      @@manikanta6183 haha

  • @Satyam-je4tb
    @Satyam-je4tb 3 หลายเดือนก่อน

    this is already constant space because we are only increasing the frequency not the element, element can only be 0 and 1, isn't it.

  • @Student-j4u
    @Student-j4u 6 หลายเดือนก่อน

    its not working for
    nums =
    [0,0,0,0,0]
    goal =
    0

    • @saikumarpeddineni
      @saikumarpeddineni 6 หลายเดือนก่อน

      No it works in this case too

    • @Student-j4u
      @Student-j4u 6 หลายเดือนก่อน

      Yeah

  • @alisheheryar1770
    @alisheheryar1770 5 หลายเดือนก่อน

    I am watching and I understand the code. But I can't give you a like on Instagram.
    Instagram use hi nahien krta apka bhai.

  • @tadadadadada
    @tadadadadada 6 หลายเดือนก่อน +1

    import java.util.HashMap;
    class Solution {
    public int numSubarraysWithSum(int[] nums, int goal) {
    int sum = 0;
    int count = 0;
    HashMap prefixSums = new HashMap();
    prefixSums.put(0, 1); // There's one way to have a sum of 0, by taking no elements.
    for (int num : nums) {
    sum += num;
    // If sum - goal has been seen before, it means there's a subarray ending at the current index
    // which sums to the goal.
    if (prefixSums.containsKey(sum - goal)) {
    count += prefixSums.get(sum - goal);
    }
    // Add the current sum to the map of prefix sums.
    prefixSums.put(sum, prefixSums.getOrDefault(sum, 0) + 1);
    }
    return count;
    }
    }

  • @tanmay07777
    @tanmay07777 5 หลายเดือนก่อน

    Why can't we use this solution for the original subarray problem without binary elements?

    • @sumitdas2147
      @sumitdas2147 5 หลายเดือนก่อน

      Well, I had the same doubt, I realized that in the original problem, the goal or K can be negative. This algorithm fails to handle negative sum value. Also try dry running for this case {-1, -1, 1} with k = 0, you will get the answer as zero. But the correct answer should be 1.
      Why this algorithm fails? It is because the overall sum b/w left & right can be less than K, but the current element pointed by right is where we are not sure of it, whether it is less than equal to K or not. And this algo add that case in the overall count. Basically, this algo fails to handle negative integers. If someone has a better explanation, please continue this thread.

    • @brokegod5871
      @brokegod5871 4 หลายเดือนก่อน

      You can use that. I copy pasted my exact code from that one and it worked in leetcode. The hashing solution I mean.

  • @divyanshsingh6668
    @divyanshsingh6668 5 หลายเดือนก่อน +2

    class Solution {
    public:
    int ans(vector& nums, int goal){
    if (goal

  • @riaa55
    @riaa55 9 วันที่ผ่านมา +1

    Understood

  • @Shivi32590
    @Shivi32590 4 หลายเดือนก่อน

    understood

  • @MJBZG
    @MJBZG 3 หลายเดือนก่อน

    understood