Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | Leetcode 1438 |Detailed

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



Duration: 49:01
10,048 views
492


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 24th Video of our Playlist "Sliding Window : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a good and standard Sliding Window Problem : Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | 2 Approaches | Dry Runs | Thought Process | Leetcode 1438 | codestorywithMIK

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.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | 2 Approaches | Dry Runs | Thought Process | Leetcode 1438 | codestorywithMIK
Company Tags : UBER
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/longest...


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

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

Summary :
Approach-1: Using Sliding Window + Heap

Algorithm: This approach employs two heaps (priority queues) to maintain the maximum and minimum values within the current sliding window.
Max-Heap: Keeps track of the maximum values.
Min-Heap: Keeps track of the minimum values.
Both heaps store pairs of values and their indices.
As the window slides, the heaps are updated to ensure that the difference between the maximum and minimum values within the window does not exceed the specified limit.
If the difference exceeds the limit, the start of the window (i) is adjusted, and elements are popped from the heaps if they fall outside the new window.
The length of the longest valid subarray is continuously updated.
Time Complexity: O(n log n) due to heap operations.
Space Complexity: O(n) to store elements in the heaps.
Approach-2: Using Sliding Window + Multiset

Algorithm: This approach uses a multiset to maintain all elements in the current sliding window, allowing efficient access to the minimum and maximum values.
As new elements are added to the window, they are inserted into the multiset.
If the difference between the maximum and minimum values exceeds the limit, the start of the window (i) is incremented, and the corresponding element is removed from the multiset.
The length of the longest valid subarray is updated in each iteration.
Time Complexity: O(n log n) due to multiset operations (insertions and deletions).
Space Complexity: O(n) to store elements in the multiset.
Comparison

Both approaches use a sliding window technique combined with a data structure that supports efficient retrieval of the minimum and maximum values within the window.
Approach-1 (Using Heaps):
More complex due to maintaining two heaps.
Slightly more operations required to keep the heaps balanced and valid.
Approach-2 (Using Multiset):
Simpler to implement.
Direct access to the minimum and maximum values using rbegin() and begin().
Both approaches have the same time and space complexity but differ in the data structures used and the specific implementation details.

✨ Timelines✨
00:00 - Introduction

#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 #newyear2024




Other Videos By codestorywithMIK


2024-06-28Query Sum II | Segment Tree Concepts & Qns | Video 5 | codestorywithMIK
2024-06-28Longest Palindromic Substring | Recursion Memo | Bottom Up | DP On Strings | Leetcode 5
2024-06-28Range Minimum Query | Segment Tree Concepts & Qns | Video 6 | codestorywithMIK
2024-06-27All Ancestors of a Node in a Directed Acyclic Graph | 3 Approaches | Leetcode 2192 |codestorywithMIK
2024-06-26Maximum Total Importance of Roads | Thought Process | Leetcode 2285 | codestorywithMIK
2024-06-25Find Center of Star Graph | 2 Simple Approaches | Leetcode 1791 | codestorywithMIK
2024-06-24Balance a Binary Search Tree | Simple Explanation | Leetcode 1382 | codestorywithMIK
2024-06-23Binary Search Tree to Greater Sum Tree | Brute | Better | Optimal | Leetcode 1038 | codestorywithMIK
2024-06-23Minimum Number of K Consecutive Bit Flips | 3 Approaches | Detailed | Leetcode 995 | 3191
2024-06-22Segment Tree | Why size is 4*n | With Proof | Video 4
2024-06-21Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | Leetcode 1438 |Detailed
2024-06-19Grumpy Bookstore Owner | Simplest Thought Process | Leetcode 1052 | codestorywithMIK
2024-06-18Magnetic Force Between Two Balls | Simple Thought Process | Leetcode 1552 | codestorywithMIK
2024-06-17Segment Tree | Range Sum Query | Story To Code | Video 3
2024-06-17Minimum Number of Days to Make m Bouquets | Simple Thought Process| Leetcode 1482 | codestorywithMIK
2024-06-16Most Profit Assigning Work | Multiple Approaches | With Intuition | Leetcode 826 | codestorywithMIK
2024-06-16Segment Tree | Update Query | Story To Code | Video 2
2024-06-15Segment Tree | Introduction | Basics | Build Segment Tree | Video 1 | codestorywithMIK
2024-06-14Patching Array | Thought Process | Dry Runs | GOOGLE | Leetcode 330 | codestorywithMIK
2024-06-13Minimum Increment to Make Array Unique | Sorting | Counting Sort | Leetcode 945 | codestorywithMIK
2024-06-13IPO | Easy Beginner Friendly | Story To Code | Leetcode 502 | codestorywithMIK