3105. Longest Strictly Increasing or Strictly Decreasing Subarray | Array | Sliding Window

preview_player
Показать описание
In this video, I'll talk about how to solve Leetcode 3105. Longest Strictly Increasing or Strictly Decreasing Subarray | Array | Sliding Window

Let's Connect:

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
Рекомендации по теме
Комментарии
Автор

bro cant we use sliding window logic and take two function strictly inc and strictly dec and get the max from the values we from from the two function?

jaisingh
Автор

class Solution {
public:
int nums) {
int maxi=0;
int n = nums.size(), count1=1, count2=1;
for(int i=1;i<n;i++) {
if(nums[i] > nums[i-1]) {//increasing
count1++;
}
else{
maxi=max(maxi, count1);
count1=1;
}
if(nums[i] < nums[i-1]) {//decreasing
count2++;
}
else{
maxi=max(maxi, count2);
count2=1;
}
}
maxi=max({maxi, count1, count2});
return maxi;
}
};

HariKrishnan-ffhf