Binary Subarrays With Sum | 2 Approaches | Detailed Explanation | Leetcode 930
iPad PDF Notes - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Leetcode-930-Binary%20Subarrays%20With%20Sum.pdf
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 15th Video of our Playlist "Sliding Window : Popular Interview Problems".
In this video we will try to solve a very good Sliding Window problem : Binary Subarrays With Sum | 2 Approaches | Detailed Explanation | Leetcode 930
Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with the hashtag #codestorywithmik & feel free to tag me.
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Binary Subarrays With Sum | 2 Approaches | Detailed Explanation | Leetcode 930
Company Tags : Will update soon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Sliding%20Window/Binary%20Subarrays%20With%20Sum.cpp
Leetcode Link : https://leetcode.com/problems/binary-subarrays-with-sum/
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Approach Summary :
Approach-1 (Simple prefix sum):
This approach utilizes a cumulative sum technique along with a map to efficiently count the number of subarrays with a given sum. It maintains a cumulative sum while traversing the array, updating it at each step. If the current cumulative sum equals the goal, it increments the count. Additionally, it checks if there exists a previous cumulative sum that, when subtracted, gives the desired goal. If so, it adds the corresponding count from the map. Finally, it updates the map with the current cumulative sum. This approach has a time complexity of O(n) and a space complexity of O(n).
Approach-2 (Using Sliding Window):
This approach utilizes a sliding window technique to find subarrays with the given sum. It iterates through the array, maintaining two pointers i and j to define the window. The window expands by moving the j pointer and contracts by moving the i pointer. It keeps track of the sum within the window and the count of zeros encountered before reaching the goal sum. Whenever the sum equals the goal, it calculates the number of subarrays using the count of prefix zeros and increments the overall count accordingly. This approach handles cases where the array contains zeros, making it slightly more complex. It has a time complexity of O(n) and a space complexity of O(1).
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
02:21 - Brute Force
03:04 - Recap Leetcode-560
05:06 - Optimal Approach-1
14:13 - Coding Approach-1
16:08 - Approach-2 Sliding Window
24:10 - Multiple Dry Runs
31:18 - Coding Sliding Window Approach-1
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear