Number of Sub-arrays With Odd Sum | Brute Force | Better | Optimal | Leetcode 1524 |codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=_tAArozuTwA



Game:
Duration: 0:00
9,573 views
569


iPad PDF Notes - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad PDF Notes/Leetcode - 1524.pdf
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A

Hi Everyone, this is the 143rd video of our Playlist "Arrays 1D/2D : Popular Interview Problems".
Now we will be solving a good Graph problem - Number of Sub-arrays With Odd Sum | Brute Force | Better | Optimal | Detailed | Leetcode 1524 | codestorywithMIK

Problem Name : Number of Sub-arrays With Odd Sum | Brute Force | Better | Optimal | Detailed | Leetcode 1524 | codestorywithMIK
Company Tags : will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Cumulative_Sum(Prefix Array)/Number of Sub-arrays With Odd Sum.cpp
Leetcode Link : https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Segment Tree Concepts Playlist :    • Segment Tree | Introduction | Basics ...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
Trie Playlist -    • Word Search II (Google, Amazon, Meta,...  
Difference Array Technique: Concepts & Qns :    • Introduction | What | How | Differenc...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel :    / @codestorywithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝


Video Summary :
Approach-1 (Brute Force): This method considers all possible subarrays and checks if their sum is odd. Due to its O(n³) complexity, it is highly inefficient for large inputs.

Approach-2 (Better Brute Force): Instead of recalculating sums for each subarray from scratch, it maintains a running sum. This reduces the time complexity to O(n²), making it slightly better but still suboptimal.

Approach-3 (Optimal using Prefix Sum Array):
The idea is to use a prefix sum to track cumulative sums efficiently. Instead of checking each subarray individually, we count how many prefix sums are odd or even.

If the current prefix sum is even, the number of valid subarrays is equal to the count of odd prefix sums encountered so far.
If the prefix sum is odd, the valid subarrays count is derived from the even prefix sums seen previously.
This approach helps us count odd-sum subarrays efficiently in O(n) time using additional space for prefix sums.
Approach-4 (Optimal using Constant Space): Instead of maintaining a prefix sum array, we only track two values: the count of odd and even prefix sums seen so far. This allows us to achieve O(n) time and O(1) space, making it the most efficient approach.

✨ Timelines✨
00:00 - Introduction
0:22 - Motivation
0:53 - Problem Explanation
1:53 - Brute Force
4:29 - Better Brute Force
7:05 - Optimal Approach Intuition Building
10:43 - Already studied concept example
12:11 - Dry Run for Optimal Approach
27:41 - Coding Optimal using O(n) space
31:00 - Coding Optimal using O(1) space

#MIK #mik #Mik
#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 #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik




Other Videos By codestorywithMIK


2025-03-05Find Missing and Repeated Values | Mathematical Proof | Leetcode 2965 | codestorywithMIK
2025-03-04Count Total Number of Colored Cells | Maths Proof | 2 Approaches | Leetcode 2579 | codestorywithMIK
2025-03-03Check if Number is a Sum of Powers of Three | Maths Proof | 3 Ways | Leetcode 1780 |codestorywithMIK
2025-03-02Partition Array According to Given Pivot | Multiple Approaches | Leetcode 2161 | codestorywithMIK
2025-03-01Merge Two 2D Arrays by Summing Values | Multiple Approaches | Leetcode 2570 | codestorywithMIK
2025-03-01Nasha hai bhai 🥹
2025-02-27Recursion : The Ultimate Guru 🔥
2025-02-27Aamchi Mumbai, jithe sab kuch possible aahe ❤️
2025-02-26Length of Longest Fibonacci Subsequence | Recursion Memo | Bottom Up |Leetcode 873| codestorywithMIK
2025-02-25Maximum Absolute Sum of Any Subarray | Kadane's Algorithm | Leetcode 1749 | codestorywithMIK
2025-02-24Number of Sub-arrays With Odd Sum | Brute Force | Better | Optimal | Leetcode 1524 |codestorywithMIK
2025-02-23Thoda bed rest lelu ? 🥹
2025-02-22Recovering ❤️‍🩹 🙏
2025-02-22Construct Binary Tree from Preorder and Postorder Traversal | Leetcode 889 | codestorywithMIK
2025-02-22Another Success Story | Microsoft
2025-02-21Recover a Tree From Preorder Traversal | Easy DFS Simulation | Leetcode 1028 | codestorywithMIK
2025-02-20Find Elements in a Contaminated Binary Tree | BFS | DFS | Leetcode 1261 | codestorywithMIK
2025-02-18The k-th Lexicographical String of All Happy Strings of Length n | Leetcode 1415 | codestorywithMIK
2025-02-17Construct Smallest Number From DI String | Easy Approaches | Leetcode 2375 | codestorywithMIK
2025-02-16Letter Tile Possibilities | 2 Ways | Using Standard Template | Leetcode 1079 | codestorywithMIK
2025-02-15Construct the Lexicographically Largest Valid Sequence | Detailed | Leetcode 1718 | codestorywithMIK