Longest Nice Subarray | Brute Force | Better | Optimal | Dry Runs | Leetcode 2401 | codestorywithMIK

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



Game:
Duration: 0:00
12,193 views
708


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
Sliding Window Playlist -    • Sliding Window : Popular Interview Pr...  

Hi Everyone, this is the 37th video of our Playlist "Sliding Window : Popular Interview Problems".Now we will be solving a good Sliding Window problem - Longest Nice Subarray | Brute Force | Better | Optimal | Dry Runs | Leetcode 2401 | codestorywithMIK

We will understand from Brute Force and then with a better approach to know why it is a Sliding Window Problem and then we will use the same Khandani Template of Sliding Window.We will do a deep dive and complete dry run.

Problem Name : Longest Nice Subarray | Brute Force | Better | Optimal | Dry Runs | Leetcode 2401 | codestorywithMIK
Company Tags : will update later
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Sliding Window/Longest Nice Subarray.cpp
Leetcode Link : https://leetcode.com/problems/longest-nice-subarray/description/

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 checks every possible subarray to determine if it is "nice" by ensuring no two elements share common bits. It iterates through all subarrays and updates the result accordingly.Approach-2 (Better):
Instead of checking all subarrays independently, this approach maintains a bitmask while iterating. It stops extending a subarray once a conflict is detected, reducing unnecessary checks.Approach-3 (Sliding Window):
This method uses a two-pointer technique to dynamically adjust the window size. When a conflict arises, it shrinks the window from the left while maintaining the largest valid subarray found so far.


 Timelines
00:00 - Introduction
0:25 - Motivation
0:45 - Problem Explanation
2:15 - Brute Force Approach
5:30 - How to check Nice in O(n)
17:31 - Better Approach
23:14 - Why Sliding Window
33:15 - Coding it up


#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 #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #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-28Binary Exponentiation | Fast Exponentiation | Detailed For Beginners | codestorywithMIK
2025-03-27Find the K-th Largest or Smallest in O(n) using nth_element | Competitive Programming Hack
2025-03-26Minimum Index of a Valid Split | 2 Approaches | Leetcode 2780 | codestorywithMIK
2025-03-25Minimum Operations to Make a Uni-Value Grid | Detailed Simple Maths Proof | Leetcode 2033 | MIK
2025-03-24Check if Grid can be Cut into Sections | Merge Intervals | Leetcode 3394 | Leetcode 56 | Detailed
2025-03-23Count Days Without Meetings | Simplest Explanation | Leetcode 3169 | codestorywithMIK
2025-03-22Number of Ways to Arrive at Destination | Straight Forward Simple | Leetcode 1976 | codestorywithMIK
2025-03-22Why I Will NEVER Promote Paid DSA Courses! 🚫 The Truth You Need to Know | codestorywithMIK
2025-03-21Count the Number of Complete Components | Multiple Approaches | Leetcode 2685 | codestorywithMIK
2025-03-21Find All Possible Recipes from Given Supplies | Brute Force | Optimal | Leetcode 2115
2025-03-17Longest Nice Subarray | Brute Force | Better | Optimal | Dry Runs | Leetcode 2401 | codestorywithMIK
2025-03-16Divide Array Into Equal Pairs | 5 Approaches | Leetcode 2206 | codestorywithMIK
2025-03-15Minimum Time to Repair Cars | With Minute Details | Leetcode 2594 | codestorywithMIK
2025-03-14House Robber IV | Brute Force | Optimal | Leetcode 2560 | codestorywithMIK
2025-03-14DSA Shorts with MIK - 11 | Avoid TLE in Competitive Programming with Fast I/O 🔥 | Part 2
2025-03-13Maximum Candies Allocated to K Children | Brute Force | Optimal | Leetcode 2226 | codestorywithMIK
2025-03-12Zero Array Transformation II | Brute Force | Better | Leetcode 3356 | codestorywithMIK
2025-03-11Maximum Count of Positive Integer and Negative Integer | Leetcode 2529 | codestorywithMIK
2025-03-10Number of Substrings Containing All Three Characters | Dry Runs | Leetcode 1358 | codestorywithMIK
2025-03-10Are mummy 🥹
2025-03-09Count of Substrings Containing Every Vowel and K Consonants II | Leetcode 3306 | codestorywithMIK