2058. Find the Minimum and Maximum Number of Nodes Between Critical Points | Greedy | Linked List
Vložit
- čas přidán 6. 09. 2024
- In this video, I'll talk about how to solve Leetcode 2058. Find the Minimum and Maximum Number of Nodes Between Critical Points | Greedy | Linked List
Let's Connect:
📱Discord (Join Community) : / discord
📝Linkedin: / aryan-mittal-0077
📸 Instagram: / codewitharyanbhai
💻 Twitter - / aryan_mittal007
🤖 Github: github.com/ary...
About Me:
I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
✨ Timelines✨
✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms
Okay July easy going so far, means next week is gonna be 🤐, what do you guys think 💭
aryan bhai pls check mail by me
For sure😢😢
hello bhai I have used your tips and got job. Thanks brother.
Great Explanation 🤩
great explanation, I think there were some problem with the mic while you were recording this.
my solution:
similar approach
class Solution {
public:
vector nodesBetweenCriticalPoints(ListNode* head) {
vector ans(2,-1);
ListNode *slow=new ListNode();
ListNode *curr=head;
ListNode *fast=head->next;
if(!fast || !fast->next) return ans;
int firstcritical=-1;
int lastcritical=-1;
int mindistance=INT_MAX;
int count=1;
slow=curr;
curr=fast;
fast=fast->next;
while(fast){
if((curr->val>slow->val && curr->val>fast->val) || (curr->valval && curr->valval)){
if(firstcritical==-1){
firstcritical=count;
}
else{
mindistance=min(mindistance,count-lastcritical);
ans[1]=count-firstcritical;
ans[0]=mindistance;
}
lastcritical=count;
}
count++;
slow=curr;
curr=fast;
fast=fast->next;
}
return ans;
}
};
@15:21 shouldn’t ans[1] be equal to max of ans[1], id-first rather than max of ans[0], id-first??
aryan bhai check krlijiye pls goldman ka issue aapse mail kr rkha
Easy Question if u are familiar with linked list.
Solved on my own
first comment
❤️❤️🫡