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 🥺
@ankurverma40422 ай бұрын
First like and first comment. I solved this question with the help of the deque method
@ARYANMITTAL2 ай бұрын
Awesome man 😮💨🫡❤️
@prajitbanerjee82262 ай бұрын
Last approach was great man!!!
@rahulz337Ай бұрын
How about using 2 segment trees ? One to track maximum the other for minimum
@krishpoptani78622 ай бұрын
The video is informative, first approach was very intuitive. Never thought of 2nd and 3 rd approach
@varunjain39472 ай бұрын
Bro what an explanation you cover a lot of concepts with this question thankyou brother and make such videos daily to help us
@user-xc6ez1kj6q2 ай бұрын
Awesome video!
@IK-xk7ex2 ай бұрын
THank you! I didn't hear previously about `multiset` data structure...
@MaheshKumar-mh9mj2 ай бұрын
so any 2 elements means all possible 2 elements .. not any of the 2 elements in subarray???
@arjunc14822 ай бұрын
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
@rushirajparekh90792 ай бұрын
Hi Aryan. It's quite fine explanation. I have one question; can we use ordered_map instead of multiset?
@SidharthjainSingla2 ай бұрын
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
@shashankarora29452 ай бұрын
Amazing
@xenondeltor79252 ай бұрын
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-hn6wj2 ай бұрын
🙌🙌🙌
@atulrulers2 ай бұрын
Just maintain the indexes of min element and max element in window, this will require constant space
@codebreaker65782 ай бұрын
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
@atulrulers2 ай бұрын
@@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
@atulrulers2 ай бұрын
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.
@ITACH16882 ай бұрын
Bhaiya kal ke Leetcode ka Q3 soln chahiye.. mera TLE aa rha tha...
@mohit77172 ай бұрын
RIght, Mera v TLE agya ta 3rd question me
@ajringtones95742 ай бұрын
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; } }
@ITACH16882 ай бұрын
@@ajringtones9574 thanks bhai
@mohit77172 ай бұрын
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-fz2yn2 ай бұрын
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-mf1dc2 ай бұрын
@@Sai-fz2yn yes excepted
@kergeysarjakin55922 ай бұрын
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🙃
@ajayprabhu4652 ай бұрын
puri dekhi 1.5 hrs lagi , par pura samajh aya .
@harshdiwase19412 ай бұрын
I didnt understand the min heap max heap approach , did it using the multiset by taking hint, atleast my thought process is developing
@SidharthjainSingla2 ай бұрын
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
@karankamath70312 ай бұрын
Sorry, I think, you are a great engineer, but unfortunately, not a teacher.
@rohitkumarpilania942 ай бұрын
Looks like you are none
@karankamath70312 ай бұрын
@@rohitkumarpilania94 yeah just like you.
@SidharthjainSingla2 ай бұрын
Yeah , he was not able to intuitively explain the last deque approach
@SidharthjainSingla2 ай бұрын
But yeah that happens , but it not means he is not a great teacher, his other videos are mind blowing
@Dota2Vibes2 ай бұрын
I think he explained really well all the approaches personally
@hardiksinghbhadoria67822 ай бұрын
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