This channel features Programming, MATHS ,Data Structures & Algorithms,Technology,Tutorials etc. Browse our channel to know more. SUBSCRIBE to never miss our videos :) SUGGEST your likes and dislikes in our videos so that we can improve on our flaws and give you a seamless experience.
Пікірлер
very good explanation and technique
Thanks
Bro if the question ask for 5 mark.. How much mark will get if i write this method🫠
10. extra marks for making my life easy in checking 😂
nice explanation
i love you
What if the array is made up of floats something like 0.76546, 2, 0.65, ....
amazing explanation !!
Thanks
Amazing, just amazing, after 4/5 videos, this is the only guy that makes sense!
hates(mom,bua). 1:25
makasih bang, besok aku exam jadi mengerti
❤
just awsome made my code just after first 3 min of viedo .
Man you blew my mind 🤯🤯 Is this always this easy or am I the one who's tripping??
you are Robot.
if you r to merge the sorted chunk and again sort it, why the heck would you sort the chunk first... just merge everything and sort it there... your step is taking double the time. geez youtube ka 50 IQ ka instructor
You can choose any inplace algorithm like heapsort. Then find sorted array with O(1) space and then write back the chunks in contiguous memory in the drive. That will effective be done in O(1) extra space and O(NlogN) time complexity.
great explaination!
thanks :)
Today I have attended Zoho on campus drive.This question is asked in basic programming round💯.
nice :)
what is this algorithm called?
dutch national flag maybe :)
Now I will not forget this, thanks
great
this is the best video on articulation point, hats off to your comendable efforts 👑
thanks
I've watched many of your videos. Your explanations are always very easy to understand. Thank you for creating these videos; you are doing so much good.
thanks :)
Why we are not moving i back to previous + 1 position?
thanku for explaining pre in and post order in such a easy way my 5 month class converted into 7mints🫡
woww :)
Superb explanation ❤
thanks :)
Thank you 🎉🎉
welcome
Nice explanation!
thanks
good explanation but I need to implement it using for loops not recursive functions (it is more complex)
Thanks
welcome
perfect explanation
thanks
// Bruteforce Approach class Solution { public int subarraySum(int[] arr, int k) { int[] prefixSum = new int[arr.length]; for (int i = 0; i < arr.length; i++) { if (i == 0) { prefixSum[i] = arr[i]; } else { prefixSum[i] = prefixSum[i - 1] + arr[i]; } } int count = 0; for (int start = 0; start < arr.length; start++) { for (int end = start; end < arr.length; end++) { if (findSubarraySum(prefixSum, start, end) == k) { count++; } } } return count; } private int findSubarraySum(int[] prefixSum, int startIndex, int endIndex) { if (startIndex == 0) { return prefixSum[endIndex]; } return prefixSum[endIndex] - prefixSum[startIndex - 1]; } } // Better Approach class Solution { public int subarraySum(int[] arr, int k) { int count = 0; for (int start = 0; start < arr.length; start++) { int subArraySum = 0; for (int end = start; end < arr.length; end++) { subArraySum += arr[end]; if (subArraySum == k) { count++; } } } return count; } } //Optimal Approach class Solution { public int subarraySum(int[] arr, int k) { Map<Integer, Integer> sumFrequencyMap = new HashMap<>(); int count = 0, prefixSum = 0; for (int val : arr) { prefixSum += val; if (prefixSum == k) { count++; } if (sumFrequencyMap.containsKey(prefixSum - k)) { count += sumFrequencyMap.get(prefixSum - k); } sumFrequencyMap.put(prefixSum, sumFrequencyMap.getOrDefault(prefixSum, 0) + 1); } return count; } } /* int[] arr = {3, 0, 7 ,2 ,-3 ,1 ,4 ,2}; and k = 7 Let's break down the method's implicit check for all subarrays: Possible Subarrays and Their Sums: Subarrays starting from index 0: [3] : Sum = 3 [3, 0] : Sum = 3 [3, 0, 7] : Sum = 10 [3, 0, 7, 2] : Sum = 12 [3, 0, 7, 2, -3] : Sum= 9 [3, 0, 7, 2, -3 ,1] : Sum= 10 [3, 0, 7, 2, -3, 1, 4]: Sum= 14 [3, 0, 7, 2, -3, 1, 4 , 2]: Sum= 16 Subarrays starting from index 1: [0] : Sum = 0 [0, 7] : Sum = 7 [0, 7, 2] : Sum = 9 [0, 7, 2, -3] : Sum = 6 [0, 7, 2, -3, 1] : Sum = 7 [0, 7, 2, -3, 1, 4] : Sum = 11 [0, 7, 2, -3, 1, 4, 2] : Sum = 13 Subarrays starting from index 2: [7] : Sum = 7 [7, 2] : Sum = 9 [7, 2, -3] : Sum = 6 [7, 2, -3, 1] : Sum = 7 [7, 2, -3, 1, 4] : Sum = 15 [7, 2, -3, 1, 4 , 2] : Sum = 17 Subarrays starting from index 3: [2] : Sum = 2 [2, -3] : Sum = -1 [2, -3, 1] : Sum = 0 [2, -3, 1, 4] : Sum = 4 [2, -3, 1, 4, 2] : Sum = 6 Subarrays starting from index 4: [-3] : Sum = -3 [-3, 1] : Sum = -2 [-3, 1, 4] : Sum = 2 [-3, 1, 4, 2] : Sum = 4 Subarrays starting from index 5: [1] : Sum = 1 [1, 4] : Sum = 5 [1, 4, 2] : Sum = 7 Subarrays starting from index 6: [4] : Sum = 4 [4, 2] : Sum = 6 Subarrays starting from index 7: [2] : Sum = 2 Observation : In first iteration the direct lookup(for prefixSum= 3) is for subarray [3] (doesnot sum to 7) and map lookup(for repetition of (prefixSum-7) i.e -4) is for [] subarray, which does not sum to 7 so ignored. (Hence count=0 and Map:{3:1}) In second iteration the direct lookup(for prefixSum= 3) is for subarray [3 ,0] (doesnot sum to 7) and the map lookup (for repetition of (prefixSum-7) i.e -4) is for subarray [0] , which does not sum to 7 so ignored. (Hence count =0 and Map: {3:2}) In third iteration the direct lookup(for prefixSum= 10) is for subarray[3 ,0 ,7] (doesnot sum to 7) and the map lookup(for repetition of (prefixSum-7)= 3) is for subarrays [0, 7] and [7] , both of these subarrays sum to 7 so include it. (i.e count=0+1+1= 2 i.e [0, 7] and [7] and Map: {3:2,10:1}) In fourth iteration the the direct lookup(for prefixSum= 12) is for subarray [3 , 0, 7, 2] (doesnot sum to 7) and the map lookup (for repetition of (prefixSum-7)= 5) is for subarrays [0, 7, 2] , [7, 2] and [2] but none of these subarrays sum to 7 so ignored (i.e count=2 i.e i.e [0, 7] and [7] and Map: {3:2,10:1,12:1}) In fifth iteration the the direct lookup(for prefixSum= 9) is for subarray [3, 0, 7, 2, -3] (doesnot sum to 7) and the map lookup (for repetition of (prefixSum-7)= 2) is for subarrays [0, 7, 2, -3] , [7, 2, -3] and [2, -3] and [-3] but none of these subarray sum to 7 so ignored (i.e count=2 i.e [0, 7] and [7] and Map: {3:2,10:1,12:1,9:1}) In sixth iteration the the direct lookup(for prefixSum= 10) is for subarray [3, 0, 7, 2, -3 ,1] (doesnot sum to 7) and the map lookup (for repetition of (prefixSum-7)= 3) is for subarrays [0, 7, 2, -3, 1], [7, 2, -3, 1] and [2, -3, 1] and [-3, 1] , two of these subarray sum to 7 (i.e count=2+1+1=4 i.e [0, 7], [7], [0, 7, 2, -3, 1] and [7, 2, -3, 1] and Map: {3:2,10:2,12:1,9:1}) In seventh iteration the the direct lookup(for prefixSum= 14) is for subarray [3, 0, 7, 2, -3, 1, 4] (doesnot sum to 7) and the map lookup (for repetition of (prefixSum-7)= 7) is for subarrays [0, 7, 2, -3, 1, 4] , [7, 2, -3, 1, 4] , [2, -3, 1, 4] , [-3, 1, 4] , [1, 4] and [4] , None of these subarray sum to 7 (i.e count=4 i.e [0, 7] ,[7], [0, 7, 2, -3, 1] and [7, 2, -3, 1] and Map: {3:2,10:2,12:1,9:1,14:1}) In eight iteration the the direct lookup(for prefixSum= 16) is for subarray [3, 0, 7, 2, -3, 1, 4 , 2] (doesnot sum to 7) and the map lookup (for repetition of (prefixSum-7)= 9) is for subarrays [0, 7, 2, -3, 1, 4, 2] , [7, 2, -3, 1, 4 , 2] , [2, -3, 1, 4 , 2] , [-3, 1, 4, 2] , [1, 4, 2] , [4, 2] and [2] ,one of these subarray sum to 7 (i.e count=4 + 1 = 5 i.e [0, 7] ,[7], [0, 7, 2, -3, 1], [7, 2, -3, 1] and [1, 4, 2] and Map: {3:2,10:2,12:1,9:1,14:1,16:1}) */
fucking legend lov u adore u
:)
Such clear explanation and visual drawings are the reason why u r ny go to person for DSA , you are #1 man
thanks :)
Well explained dude! 😂❤
thanks :)
very clear explaination.
thanks :)
I'm satisfied with the proof on the time complexity. What about the space complexity? May I ask why it is O(logN)?
log N is the height of the tree. we are building heap inplace
you are awesome keep going bro
thanks :)
Thank you ... This is very clear
thanks :)
Thank you very much
welcome
thank you very much
welcome
thank you very much
welcome
Thanks 😢❤
welcome :)
bhai ye to pta hi hota hai you need to find the ans without using inorder aise to bst ke saare que hote hi hai inorder se interview mai aise allowed nai krte
How to contact for you. I come to VIỆT NAM
didn't notice new intro look. nice!
Such a great explanation
thanks :)
😂😂😂 bro simply too good 👍
:)
Best explanation I found!
thanks :)
Great explanation. Thank you
here for daily solution bud !1
welcome :)
Sir, where i can find the problems
can u send the code for this problem..i got wrong an"Could you please provide the code for this problem? I received an incorrect answer." swer
Best solution is still O(N)