No video

1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | 3 Approaches

  Рет қаралды 5,205

Aryan Mittal

Aryan Mittal

Күн бұрын

Пікірлер: 39
@ARYANMITTAL
@ARYANMITTAL 2 ай бұрын
Have added Timestamps for anyone just here to solve the problem, just watch starting 14mins 🌚, for others watch depending on jitni himmaat bachi ho 💀 . Sub nhi bharvaye naa aap logo ne 🥺
@ankurverma4042
@ankurverma4042 2 ай бұрын
First like and first comment. I solved this question with the help of the deque method
@ARYANMITTAL
@ARYANMITTAL 2 ай бұрын
Awesome man 😮‍💨🫡❤️
@prajitbanerjee8226
@prajitbanerjee8226 2 ай бұрын
Last approach was great man!!!
@rahulz337
@rahulz337 Ай бұрын
How about using 2 segment trees ? One to track maximum the other for minimum
@krishpoptani7862
@krishpoptani7862 2 ай бұрын
The video is informative, first approach was very intuitive. Never thought of 2nd and 3 rd approach
@varunjain3947
@varunjain3947 2 ай бұрын
Bro what an explanation you cover a lot of concepts with this question thankyou brother and make such videos daily to help us
@user-xc6ez1kj6q
@user-xc6ez1kj6q 2 ай бұрын
Awesome video!
@IK-xk7ex
@IK-xk7ex 2 ай бұрын
THank you! I didn't hear previously about `multiset` data structure...
@MaheshKumar-mh9mj
@MaheshKumar-mh9mj 2 ай бұрын
so any 2 elements means all possible 2 elements .. not any of the 2 elements in subarray???
@arjunc1482
@arjunc1482 2 ай бұрын
How can we be sure that the front will always contain the elements which are lesser than the minimum index,since we are popping from the front
@rushirajparekh9079
@rushirajparekh9079 2 ай бұрын
Hi Aryan. It's quite fine explanation. I have one question; can we use ordered_map instead of multiset?
@SidharthjainSingla
@SidharthjainSingla 2 ай бұрын
I tried it with two ordered maps and the max value i was storing with -nums[j] trick because the if nums[j] is maximum in window then-nums[j] will be least but unfortunately it failed , some runtime error was coming and the code was logically correct and also that condition if mp[nums[j]] == 0 so do mp.erase(nums[j]) but also the runtime error was coming and also when keys are negative, in the max ordered map , i was not able to access the key with this method mp[nums[j]] because -ve indices not exist so i used mp.at(nums[j]) but it was failing
@shashankarora2945
@shashankarora2945 2 ай бұрын
Amazing
@xenondeltor7925
@xenondeltor7925 2 ай бұрын
I have seen a lot of comments on people struggling with Min and Max heap including me,🥲 Like this comment you want Aryan bhaiya to make a video on the basics and in dept analysis of priority queue(MIN heap and MAX heap) , how to use them as it is a lot confusing.
@RohitKumar-hn6wj
@RohitKumar-hn6wj 2 ай бұрын
🙌🙌🙌
@atulrulers
@atulrulers 2 ай бұрын
Just maintain the indexes of min element and max element in window, this will require constant space
@codebreaker6578
@codebreaker6578 2 ай бұрын
this will not work bro , imagine your min element was at starting of your subarray and next min is at 2nd last of subarray , so you will have to iterate whole subarray to know which is next min or max element
@atulrulers
@atulrulers 2 ай бұрын
@@codebreaker6578 class Solution { public: int longestSubarray(vector& nums, int limit) { int min_el = nums[0]; int min_idx = 0; int max_el = nums[0]; int max_idx = 0; int n = nums.size(); int ans = 1; // minimum subarray size int left = 0; // left pointer int right = 0; // right pointer while (right < n) { // Update min and max elements and their indices if (min_el >= nums[right]) { min_idx = right; min_el = nums[right]; } if (max_el limit) { // Move left pointer to right of min_idx or max_idx left = min(min_idx, max_idx) + 1; // Update min_el and max_el to the new values in the window min_el = nums[left]; max_el = nums[left]; // Find new min_idx and max_idx in the new window for (int i = left; i = nums[i]) { min_idx = i; min_el = nums[i]; } if (max_el
@atulrulers
@atulrulers 2 ай бұрын
When the condition violates, it is either due to min or max, so we need to update or new min or max at right index and then based on weather it is min or max, find second min or second max from the existing window.
@ITACH1688
@ITACH1688 2 ай бұрын
Bhaiya kal ke Leetcode ka Q3 soln chahiye.. mera TLE aa rha tha...
@mohit7717
@mohit7717 2 ай бұрын
RIght, Mera v TLE agya ta 3rd question me
@ajringtones9574
@ajringtones9574 2 ай бұрын
intuition - intialize a flag = 1 and if nums[i] is !flag (i.e. 0), increase the count and toggle the flag. So the main idea is to toggle the flag whenever we encounter the alternate value. We don't need to change the array manually, just need to create it hypothetically. class Solution { public int minOperations(int[] nums) { int ans = 0; int flag = 1; for(int i = 0; i < nums.length; i++) { if(nums[i] != flag) { ans++; flag = 1 - flag; } } return ans; } }
@ITACH1688
@ITACH1688 2 ай бұрын
@@ajringtones9574 thanks bhai
@mohit7717
@mohit7717 2 ай бұрын
Cna anyone correct me please? ``` int longestSubarray(vector& nums, int limit) { int r = 0, l = 0, ans = 1; int maxi = nums[r], mini = nums[l]; while(r
@Sai-fz2yn
@Sai-fz2yn 2 ай бұрын
Left pointers should be able to move till the point in which the max diff is less than k, so it should be inside a while loop👍, also n^2 solution was accepted?
@DevJunk-mf1dc
@DevJunk-mf1dc 2 ай бұрын
​@@Sai-fz2yn yes excepted
@kergeysarjakin5592
@kergeysarjakin5592 2 ай бұрын
Very informative video, Thanks bro, you explained it very clearly in all approaches. Loved your explaination. I was thinking of heaps before solving but was unable to achieve the logic while shrinking and deleting. Multiset was never in mind🙃
@ajayprabhu465
@ajayprabhu465 2 ай бұрын
puri dekhi 1.5 hrs lagi , par pura samajh aya .
@harshdiwase1941
@harshdiwase1941 2 ай бұрын
I didnt understand the min heap max heap approach , did it using the multiset by taking hint, atleast my thought process is developing
@SidharthjainSingla
@SidharthjainSingla 2 ай бұрын
Just like the monotonic stack , in which the elements are stacked ascending or descending , it is also monotonic queue in which elements are added increasing or decreasing but one at a time in a single queue
@karankamath7031
@karankamath7031 2 ай бұрын
Sorry, I think, you are a great engineer, but unfortunately, not a teacher.
@rohitkumarpilania94
@rohitkumarpilania94 2 ай бұрын
Looks like you are none
@karankamath7031
@karankamath7031 2 ай бұрын
@@rohitkumarpilania94 yeah just like you.
@SidharthjainSingla
@SidharthjainSingla 2 ай бұрын
Yeah , he was not able to intuitively explain the last deque approach
@SidharthjainSingla
@SidharthjainSingla 2 ай бұрын
But yeah that happens , but it not means he is not a great teacher, his other videos are mind blowing
@Dota2Vibes
@Dota2Vibes 2 ай бұрын
I think he explained really well all the approaches personally
@hardiksinghbhadoria6782
@hardiksinghbhadoria6782 2 ай бұрын
Thanks a lot bhaiya..!!! tbh,Min heap and max heap wala portion thoda confusing tha,so i did from two pointers only,but veryy well explained,tysm
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00
拉了好大一坨#斗罗大陆#唐三小舞#小丑
00:11
超凡蜘蛛
Рет қаралды 16 МЛН
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 62 М.
310. Minimum Height Trees | BFS | Topological Sort | Graphs
24:47