Тёмный

Subarray with given sum 

Techdose
Подписаться 174 тыс.
Просмотров 195 тыс.
50% 1

This video explains how to find a subarray from a given array having sum equals to a given sum value. This problem is simple to solve but has been very frequently asked in programming interview rounds. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)

Опубликовано:

 

8 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 283   
@techdose4u
@techdose4u 11 месяцев назад
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037 🔴 𝐂𝐡𝐞𝐜𝐤𝐨𝐮𝐭 𝐚𝐥𝐥 𝐨𝐮𝐫 𝐂𝐨𝐮𝐫𝐬𝐞𝐬: techdose.co.in/
@CodeSuccessChronicle
@CodeSuccessChronicle 3 года назад
your brain deserves more likes 👏
@techdose4u
@techdose4u 3 года назад
😅
@mikasaackerman2694
@mikasaackerman2694 3 года назад
Nice explanation. Isn't it the same question as subarray sum equals k. You have uploaded that video too and that works for every edge case as well as negative numbers.
@techdose4u
@techdose4u 3 года назад
Thanks
@mohit7717
@mohit7717 6 месяцев назад
Thanks for sharing such a valuable programming content
@K_EC_AushoRoup
@K_EC_AushoRoup 3 года назад
What if there is more than one subarray whose sum is equal to the target sum. Then how will you modify your code? For reference see LeetCode 1171 problem. I know this 1171 LeetCode can be solved by another approach(I used Stack for solving it). But I want to apply Target sum subarray algorithm here in this question.
@supriyamanna715
@supriyamanna715 Год назад
then u use a hashmap to store the sums for each windows
@ankitchawla8487
@ankitchawla8487 4 года назад
This was a good explanation thanks a lot for making this video.
@sushobhitjakhmolaAdmin
@sushobhitjakhmolaAdmin 3 года назад
Hey what if after 10 there is 5. So when we get currentsum as 38 , adding next element -5 would make it as 33. Perhaps it isn't suitable for arrays containing negatives
@tusharnain6652
@tusharnain6652 2 года назад
yes!
@lazzyboii2573
@lazzyboii2573 2 года назад
Then to use this algorithm maybe add all the elements with the most negative number so every element will be positive
@anshumaan5285
@anshumaan5285 2 года назад
You'll have to use an array with running/prefix sum to solve if the arrays also contains negatives.
@motivation8238
@motivation8238 11 месяцев назад
yes it will work only for positive numbers, if you want to handle negatives then you have to use hashmap
@jawwadakhter5261
@jawwadakhter5261 4 года назад
really .........great explanation,u should keep on uploading like these content.
@techdose4u
@techdose4u 4 года назад
Thanks :)
@madhz007
@madhz007 11 месяцев назад
Your explanation deserves more views
@SurajKumar-cg1mm
@SurajKumar-cg1mm 4 года назад
halo bro what will we do if our first element is greater then sum { 43, 1, 17, 26, 15 } and sum is 32
@anuj4200
@anuj4200 4 года назад
If first element is greater then increment both right and left pointers.
@techdose4u
@techdose4u 4 года назад
If you find either right or left element is greater then just skip over that element.
@aryankhandelwal15
@aryankhandelwal15 3 года назад
@@techdose4u sir u should have mention this.
@AgarwalAashi
@AgarwalAashi 3 года назад
Very nicely explained!
@techdose4u
@techdose4u 3 года назад
Thanks :)
@sigma7253
@sigma7253 3 года назад
@@techdose4u what if its starts with -ve array
@abdurrehmanansari9219
@abdurrehmanansari9219 2 года назад
Copy hai code from geeks for geek site and even variable is same..
@sujitgoswami4583
@sujitgoswami4583 3 года назад
NOTE:- I'd recommend you guys to know the logic and then write a simple JAVA,C/C++ code, vector isn't much required. those who are unable to solve it with vector, here's the full solution. :) JAVA:- static void subarraySum(int n, int s, int[] arr) { int start=0,end=0,sum=0, r=0; int i=0; while(is)//if sum becomes greater { start=start+1; sum=0; i=start-1; } if(sum==s)//if we found all index { r++; end=i+1; start++; break; } i++; } if(r>0) System.out.print(start+" "+end); else System.out.print("-1"); } -------------------------------------------------------------------- C++, #include vector subarraySum(int arr[], int n, int s){ int l = 0; int r = 0; int count = 0; vector res; while (r
@techzone0131
@techzone0131 3 года назад
Bro gfg me ouput wrong bta rha h
@padiakhil7620
@padiakhil7620 2 года назад
@@techzone0131 lol same, but we need to add another if block if given sum==0 thn return -1
@shreyashyadav4169
@shreyashyadav4169 Год назад
@@padiakhil7620 yes after this condition solution is perfect 😄
@sravan.t7581
@sravan.t7581 Год назад
why not in python?
@user-nt8cn3pp5f
@user-nt8cn3pp5f 10 месяцев назад
we cannot return -1 because it is a vector@@padiakhil7620
@braj_marg
@braj_marg Год назад
thank you so much sir simple and easy explaination! radhavallabh shri harivansh
@shirish2005
@shirish2005 Год назад
Nice explaination
@senthilmurugan7304
@senthilmurugan7304 4 года назад
how to find all possible sub array consider [2,3,5,7,10,15] sum=10 here 7,3 one subset and 2,3,5 also another subset.
@prashantprajul9526
@prashantprajul9526 3 года назад
7and 3 is not a subarray
@mayurkoli4145
@mayurkoli4145 4 года назад
approach not work on array having negative numbers arr : [-1, -1, 1] target = 0, Not a generalize solution.
@techdose4u
@techdose4u 4 года назад
I have already answered on your comment 6 months back. Please search it in comment section. You asked the same question.
@mayurkoli4145
@mayurkoli4145 4 года назад
​@@techdose4u ohh sry!!!! : )
@techdose4u
@techdose4u 4 года назад
No problem :)
@suyashmisra7406
@suyashmisra7406 4 года назад
Hello friend,you're doing a great job and I am very thankful for these videos. I had a small doubt regarding your explanation of the time complexity. You said that since we're" passing" through each element a max of two times,the complexity should be O(2*N) which obviously is O(N). I think ,since incrementing left is an O(1) operation, it doesn't cause the time complexity to be O(2*N).It should still be O(N),simply because the loop will run for a max of n times(doing O(1) work each time) . Even though we get the same complexity eventually, getting the analysis wrong might be disastrous in an otherwise highly effective answer.
@jaishreesaraswat2800
@jaishreesaraswat2800 3 года назад
Even I had the same doubt , did you find its solution?
@phushyamithragauri9258
@phushyamithragauri9258 Год назад
I guess the loop ends when left and right == n ?? then there is chance of moving twice hence O(2*N).
@San2shsingh
@San2shsingh Год назад
Can you help me with python script for this
@chrisogonas
@chrisogonas 2 года назад
Very well explained! Thanks
@arijitchandra8218
@arijitchandra8218 4 года назад
is it an implementation of sliding window technique?
@techdose4u
@techdose4u 4 года назад
Yea
@tarzanyt3047
@tarzanyt3047 Месяц назад
you are amazing
@c56tejashsharan37
@c56tejashsharan37 6 месяцев назад
it will not work if there will be negative numbers in the subarray
@Kushagra_21
@Kushagra_21 4 года назад
sir your videos has helped a lot . Sir can you tell me from where should i prepare for technical mcqs . I have exam of accolite company next week. Thankyou for the help.
@techdose4u
@techdose4u 4 года назад
Well for short time, if you have GATE notes then revise DBMS and OS atleast, otherwise, just study important MCQ questions from geeks and search for top 50 and top100 MCQ questions for interviews. That should help :)
@Kushagra_21
@Kushagra_21 4 года назад
@@techdose4u thanks a lot sir
@techdose4u
@techdose4u 4 года назад
Welcome :)
@shubrochakroborty5918
@shubrochakroborty5918 2 года назад
Bro you are just awesome
@techdose4u
@techdose4u 2 года назад
Thanks :)
@gaurika4927
@gaurika4927 3 года назад
What is negative elements are also present [4,-1,-2,0,3,1] and sum 1
@tejasdonadkar9094
@tejasdonadkar9094 3 года назад
Please Explain Longest subarray with given sum using HashSet if possible
@aasifali9139
@aasifali9139 2 года назад
thx brother it was really helpful....
@057anmolkesarwani4
@057anmolkesarwani4 3 года назад
Nice one
@techdose4u
@techdose4u 3 года назад
Thanks
@arpanbarua5424
@arpanbarua5424 Год назад
Plz type the code aslo❤❤either way nice and good video🎉🎉
@askchaitanya97
@askchaitanya97 3 года назад
What of there is 9 at index 4 and sum is still 33? I mean what if we have subarray sums greater than or lower than the given sum , but not exactly equal to it?
@edenfire1221
@edenfire1221 3 года назад
Yeah, either we are looking for something else, or this is wrong.. if its 9 at index 4, it wont know the sum of index 0, 2, 3, and 4 = 33.
@vithleshkumargupta
@vithleshkumargupta 4 года назад
you are doing great work👍👍
@techdose4u
@techdose4u 4 года назад
Thanks :)
@memeologicalworld8929
@memeologicalworld8929 Год назад
But when we need to go upto n-1 then at n-1 we have our sum equal to required sum but loop again run and i=n so,loop ends and there are more problems on this when you are going to submit on gfg,leetcode,etc.🧐
@hersheynohara5887
@hersheynohara5887 4 года назад
Thanks for the video...
@techdose4u
@techdose4u 4 года назад
Welcome :)
@GdLongerHandle
@GdLongerHandle 3 года назад
what if sum = 15. right pointer will stop at 2. And till 2 we shall not have any subarray with sum =15
@selectivitism
@selectivitism 4 года назад
This solution is so damn freaking clever!
@techdose4u
@techdose4u 4 года назад
:)
@siddharthashankar8396
@siddharthashankar8396 2 года назад
Very Helpful
@ShahidAli-uq9hq
@ShahidAli-uq9hq 8 месяцев назад
Input nums = [-1,-1,1] k = 0 Use Testcase Output 0 Expected 1 ### This approach will not work for negative numbers
@kashifanwar9733
@kashifanwar9733 4 года назад
nice approach
@techdose4u
@techdose4u 4 года назад
:)
@pepetikesavasiddhardha7852
@pepetikesavasiddhardha7852 Год назад
simple yet sexy logic....
@eeshgadol
@eeshgadol 9 дней назад
Code, java , this approach with one loop!: public static ArrayList subarraySum(int[] arr, int n, int s) { ArrayList result= new ArrayList(); int left=0; int right=0; int sum=arr[left]; while(rights) { sum=sum-arr[left]; //System.out.println("sum minus left " + sum); left++; } else if(sum
@for461
@for461 2 года назад
[1,1,2] --> will fail ? for target 2 should return position 2.
@snehill7275
@snehill7275 Год назад
I am not sure if the TC is O(n) here, because in the worst case we have to move n-1 time backward on that moment TC will n x (n-1) => O(N^2) ex- [1,2,20,10,2], sum = 12 sum_will be like = 1,3,23 12) we go backward 23-1= 22 , 22-2= 20, 20-10=10 as 10 < 2 we can move forward and doing so we will ended up with answer => (3,4) pls, correct me if I am wrong.
@surajsingh-sm7qx
@surajsingh-sm7qx 3 года назад
U r awesome
@gauravborkar1345
@gauravborkar1345 3 года назад
Excellent
@Usurperhk
@Usurperhk 3 года назад
What if the left pointer become equal to or exceeds the right pointer??? FIX IT!!!!
@msahai7017
@msahai7017 4 года назад
Hi...How can we do the same thing using maps??
@srajsekhar4061
@srajsekhar4061 4 года назад
Nice explanation 👌👌👌 bro
@techdose4u
@techdose4u 4 года назад
Thanks bro :)
@vivekkumar-fk9lc
@vivekkumar-fk9lc 3 года назад
But instead of giving the longest subarray, it will return the first subarray having sum equal to k.. How would we get the largest sum
@siddeshwarvasam3075
@siddeshwarvasam3075 2 года назад
I came here after code chef long competition find lowest sub array with sum k 😶
@shashikumari4000
@shashikumari4000 3 года назад
What if sum is 9 only 5 and 4 satisfies.... Can someone explain this🙏 how will the algorithm with
@mandeepdas351
@mandeepdas351 3 года назад
the explanation is about finding subarray and not subsequence. 5 ,4 is not a subarray.
@ecstacist6749
@ecstacist6749 3 года назад
Thank you ! What if the solution elements are non_consequtive
@PankajSingh-mm3br
@PankajSingh-mm3br 3 года назад
A subarray is a contiguous part of array. An array that is inside another array
@cuteminired6550
@cuteminired6550 5 месяцев назад
​@@PankajSingh-mm3br thanks
@varun8441
@varun8441 4 года назад
what will be termination condition if we don't find and sum equal to given sum??
@techdose4u
@techdose4u 4 года назад
Termination will be when right pointer goes out of bounds, that is, when right pointer goes beyond last value in array.
@ajaygonepuri2285
@ajaygonepuri2285 Год назад
thank you sir!
@sonusangwan7898
@sonusangwan7898 5 лет назад
great video brother
@techdose4u
@techdose4u 4 года назад
Thanks :)
@leetcoder6569
@leetcoder6569 Год назад
Great
@vinayak186f3
@vinayak186f3 3 года назад
Will it work for array with some negative elements ? I think it won't , correct me if wrong
@sigma7253
@sigma7253 3 года назад
what if we start arr[0] is -ve
@yaswanthreddy372
@yaswanthreddy372 4 года назад
thanks bro,its working
@techdose4u
@techdose4u 4 года назад
Welcome :)
@dayagutte45
@dayagutte45 4 года назад
@@techdose4u plz give me solution of this Write a program to find lowest number of integers in the array that sums up the given number. In java,c,c++ only no python Write a program to find lowest number of integers in the array that sums up the given number. The program should ask user to input array of integers (“Input Array”) and the required sum (“Required Sum”). The output (“Output”) should list the lowest number of integers from the input array that sums up the “Required Sum”. Refer to examples given below. Input : Array of integers Required sum Output : Elements from array which makes sum equals to given value Example: Input Array : [10, 0, -1, 20, 25, 30] Required Sum: 45 Output: [20, 25] Required Sum: 59 Output: [10, -1, 20, 30] Required Sum: 60 Output: [10, 20, 30]
@dayagutte45
@dayagutte45 4 года назад
Can u provide a code plz
@dayagutte45
@dayagutte45 4 года назад
Can u provide a code plz
@shrimatkapoor2200
@shrimatkapoor2200 4 года назад
Isn't the number of subsets of a finite set 2^n for n cardinality of the set
@techdose4u
@techdose4u 4 года назад
You are correct. But here we are solving subarray which is continuous and not subset. So it will be N^2 for subarray.
@TechDextro
@TechDextro 3 года назад
what if there are negative elements in the array
@shafi_786
@shafi_786 2 месяца назад
thanks
@techdose4u
@techdose4u 2 месяца назад
welcome
@inderjeetchawla527
@inderjeetchawla527 4 года назад
Bhai negative elements bhi ho array me to. And Bhai jab video banao to saare cases cover Kia Karo plz.
@techdose4u
@techdose4u 4 года назад
Yes you are correct. I did not cover for negative numbers. You can do so by using the modified kadane's algorithm which works for negative numbers as well. Whenever you are given a negative number as sum then negate the sum to make it positive and also negate all the elements of the array and so sum to be found will always be positive and so you can use kadane's algorithm.
@Shanky_17
@Shanky_17 3 года назад
CAN WE USE THE SAME METHOD IF THERE ARE MORE THAN ONE SUB-ARRAY WITH SUM =K ? and is it sliding window ?
@parthanuj8611
@parthanuj8611 Год назад
I think that would not be the case when u are solving porgram in leetcode or gfg but yeah it is possible ..
@karanalang1573
@karanalang1573 4 года назад
nice explanation .. can you pls provide sample code ?
@techdose4u
@techdose4u 4 года назад
Will try to.
@gopikamurali440
@gopikamurali440 4 года назад
Pls give code
@aryankhandelwal15
@aryankhandelwal15 3 года назад
o bhai bhot hard lg rha tha
@shouryagupta8763
@shouryagupta8763 3 года назад
nice sir
@Nikita-hv5jm
@Nikita-hv5jm 3 года назад
Can we use kdane's algo for this problem?
@techdose4u
@techdose4u 3 года назад
Try 2 pointer technique.
@steevjames6720
@steevjames6720 7 месяцев назад
What if there are negative numbers ?
@eyasir2047
@eyasir2047 Год назад
Two pointer approach
@this.supratim
@this.supratim 4 года назад
Great explanation 👌
@techdose4u
@techdose4u 4 года назад
Thanks :)
@ayushkashyap8299
@ayushkashyap8299 4 года назад
I think finding all subsets of a array is O(2^n) not O(n^2). Correct me if I am wrong.
@techdose4u
@techdose4u 4 года назад
There are 2^n possible subsets of an array. So yeah, you are correct. I might have mistakenly told something, my bad.
@indyarockers
@indyarockers 4 года назад
all subsets of array is O(2^n) but consecutive subsets of an array is just O(n^2).
@secularph8424
@secularph8424 4 года назад
That's for non continuous Subarray, For continuous Subarray its O(n^2)
@techworld3043
@techworld3043 2 года назад
what software do you use to teach ?
@mameabera5852
@mameabera5852 2 года назад
what if the array is [17, 85, 93, -45, -21] and sum = 150 . this doesn't work by your algo
@prabhatkashyap8333
@prabhatkashyap8333 4 года назад
did the same on geeksforgeeks platform, showing TLE.
@techdose4u
@techdose4u 4 года назад
Should not give TLE bro :( Is there any algo to calculate below O(N) time?
@prabhatkashyap8333
@prabhatkashyap8333 4 года назад
@@techdose4u i think sliding window, thats what i am also looking for.
@techdose4u
@techdose4u 4 года назад
@@prabhatkashyap8333 yes correct.
@prabhatkashyap8333
@prabhatkashyap8333 4 года назад
@@techdose4u ide.geeksforgeeks.org/iN2jy9gvuo check this, and try to submit it on GFG, practice.geeksforgeeks.org/problems/subarray-with-given-sum/0 and tell me the mistake, why TLE?
@dhanashreegodase4445
@dhanashreegodase4445 3 года назад
Thank youThank youThank youThank you
@varun8441
@varun8441 4 года назад
what will be termination condition if we dont find and sum equal to given sum??
@AvinashJ21
@AvinashJ21 3 года назад
To move pointers we need while loop ?
@rahu1119
@rahu1119 5 лет назад
which presentation software is this ?
@ryan-bo2xi
@ryan-bo2xi 4 года назад
this uses dynamic window technique
@techdose4u
@techdose4u 4 года назад
Yea :)
@K_EC_AushoRoup
@K_EC_AushoRoup 3 года назад
Agreed
@theWrongCode
@theWrongCode 4 года назад
we changed this problem with array containing multiple subarray with given sum.
@koushikshomchoudhury9108
@koushikshomchoudhury9108 4 года назад
What you've shown is called a Sliding Window approach. Unfortunately it's an O(n^2) solution.
@techdose4u
@techdose4u 4 года назад
You are mistaken. It's O(N) only. How did you conclude O(N^2) ?
@mahesan2881
@mahesan2881 Год назад
I don't think the second method is correct, what if the first element contains 10000. That is larger than the sum 33, but if r goes one step ahead, then the currsum will not decrease but increase.
@shrimatkapoor2200
@shrimatkapoor2200 4 года назад
Also, this would only work for continuous sub-arrays would it not?
@techdose4u
@techdose4u 4 года назад
Subarray is continuous only. If something is not continuous then it is either subsequence or subset. This will work only for subarrays.
@shrimatkapoor2200
@shrimatkapoor2200 4 года назад
@@techdose4u Cool I think I was looking for the solution for subsets and target sums. Thanks for the clarification.
@vishnuthulasidosss
@vishnuthulasidosss 2 года назад
What if the array elements are 1,4,21,3,10,5 and k=33 ?
@shashankl8589
@shashankl8589 2 года назад
no subarray
@atiquesiddiqui710
@atiquesiddiqui710 4 года назад
Can you please provide the code for this
@dev.suyash
@dev.suyash 3 года назад
Sir,Can you please share code for this mentioned approach?
@akshayzade9761
@akshayzade9761 3 года назад
static ArrayList subarraySum(int[] arr, int n, int s) { ArrayList list = new ArrayList(); int left = 0, right=0; int currentsum = arr[0]; try { for(int i=1; i s) { currentsum = currentsum - arr[left]; left +=1; } } else if(currentsum > s) { currentsum = currentsum - arr[left]; left += 1; } } } catch(ArrayIndexOutOfBoundsException e) { list.add(-1); } return list; }
@ashinegi5088
@ashinegi5088 3 года назад
We can do using cumulative approach using hashmap
@techdose4u
@techdose4u 3 года назад
Yea right :)
@leetcodepythonsolutionsand9396
@leetcodepythonsolutionsand9396 4 года назад
Can you provide explanation of the DP solution?
@akshhay
@akshhay 4 года назад
Ye contigious hogyi, what if we want any subarray?
@LightningXThunderVlogs
@LightningXThunderVlogs 3 года назад
vector subarraySum(int arr[], int n, int s) // NOTE : array contains non-negative integers { if(s == 0){ // handle sum = 0 for(int i=0; i
@mrsmurf911
@mrsmurf911 2 года назад
small modification for GFG Practice: return vector{l+1,r}; instead of return vector{l,r-1};
@neghatnazir1668
@neghatnazir1668 4 года назад
hey i have a doubt regarding time complexity. e.g if we are given 1 2 5 10 ,sum=10 the second pointer is going to move till n, in this case the time complexity would b O(n^2). i am confused, can you please explain this case
@supratikpadhee4235
@supratikpadhee4235 4 года назад
to understand tc , always find how many times the particular element is processed . In this case as @tech dose explained , in the worst case scenario , we shall need to process the element 2 times , so total complexity = O(2* n )
@supratikpadhee4235
@supratikpadhee4235 4 года назад
as per your doubt , it will not be O(n^2) in the efficient approach ? why ? | | -----> window bounded by left and right pointers. | 1| , | 1 , 2| , | 1 , 2 ,5| , | 1 , 2 ,5 , 10| , | 2 ,5 , 10| , | 5 , 10| , | 10| ------> different states of the window in the worst case , our window can take 2n states , i.e increase and then decrease , so at max TC = O(2n).
@neghatnazir1668
@neghatnazir1668 4 года назад
@@supratikpadhee4235 thanks :)
@neghatnazir1668
@neghatnazir1668 4 года назад
@@supratikpadhee4235 thanks :) i checked it after
@sain3352
@sain3352 Месяц назад
This algorithm only works for limited Test cases, this does not work if there are negative values in the array for example and some edge cases. I would not recommend following this technique.
@sukdipkar8876
@sukdipkar8876 4 года назад
yaa it is going well but it exceeded time limit.
@user-so9jd2nf4s
@user-so9jd2nf4s 2 года назад
Hey, how to find multiple sub arrays?
@piyushverma5797
@piyushverma5797 4 года назад
find subarray with given sum negative numbers allowed in constant space
@tokirmanva2247
@tokirmanva2247 3 года назад
This approach won't work if there are negative numbers also.
@euphoric3464
@euphoric3464 3 года назад
I don't think this will work for all kind of arrays like a={2,4,6,8,9,10}
@kamlendratripathi8963
@kamlendratripathi8963 4 года назад
sir please explain along with code
@techdose4u
@techdose4u 4 года назад
Now I am explaining everything with code. Earlier I dint use to do that 😅
@akshayzade9761
@akshayzade9761 3 года назад
static ArrayList subarraySum(int[] arr, int n, int s) { ArrayList list = new ArrayList(); int left = 0, right=0; int currentsum = arr[0]; try { for(int i=1; i s) { currentsum = currentsum - arr[left]; left +=1; } } else if(currentsum > s) { currentsum = currentsum - arr[left]; left += 1; } } } catch(ArrayIndexOutOfBoundsException e) { list.add(-1); } return list; } Sir might have better code structure solution has this. but mine is also working as per sir approach
@chetanpadhen7780
@chetanpadhen7780 Год назад
Sir If You Also Go Through To The Code,It Will Be More Helpful. Thanks
@khushijain3574
@khushijain3574 3 года назад
which software you are using
@comradepb
@comradepb 2 года назад
Two pointer approach is not good here because the array can have negative numbers.
@sunnyvarun6652
@sunnyvarun6652 4 года назад
How will this problem be solved? int arr[]= {1,4,45,6,10,8}, target=11.
@satyamsingh_47
@satyamsingh_47 4 года назад
This is a subset sum problem which is different from a subarray sum problem
Далее
Kadanes algorithm | Longest sum contiguous subarray
7:51
Find missing number in an array
8:31
Просмотров 130 тыс.
Starman🫡
00:18
Просмотров 12 млн
Count Subarray sum Equals K | Brute - Better -Optimal
24:09
Subarray with given Sum | Python Code
11:29
Просмотров 11 тыс.
Largest Subarray with Zero Sum | Amazon | MMT
13:54
Просмотров 207 тыс.