Maximum Index || | Problem of the Day || gfg potd

preview_player
Показать описание
In this video, we will learn to solve the Maximum Index problem of geeks for geeks.

Hello Everyone, welcome to rapid coders.
Hope you like my content.
Subscribe to show your support and share with your friends so that they can also learn new things.


#arithmaticprogression #arithmetic
#gfgpractice #gfgdailychallenges #gfgdailyproblem #gfgstreek #coding #competitiveProgramming #gfgpractice #Missing_number_in_matrix
#missing_number #gfg #c++ #rapidcoder #rapid #2min #5minute
#gfgdailychallenges #gfgdailyproblem #gfg #potd #gfg #dsa #programming #matrix #cpp
#rapidcoding #rapid_coding #rapid_coder #coder #rapid_coders #rapidcoders #array #missing_number_in_array #2darray #matrix
Рекомендации по теме
Комментарии
Автор

int maxIndexDiff(int arr[], int n) {
// code here
vector<int> left_min(n, INT_MAX);
vector<int> right_max(n, INT_MIN);
int ans = 0;
left_min[0] = arr[0];
right_max[n-1] = arr[n-1];
for(int i=1;i<n;++i){
left_min[i] = min(arr[i], left_min[i-1]);
}
for(int i = n-2;i>=0;--i){
right_max[i] = max(arr[i], right_max[i+1]);
}
// for(auto i:left_min) cout<<i<<" ";
// cout<<endl;
// for(auto i:right_max) cout<<i<<" ";
// cout<<endl;

int lptr = 0, rptr = 0;
while(lptr < n && rptr < n){
if(left_min[lptr] <= right_max[rptr]){
// cout<<lptr<<" "<<rptr<<endl;
ans = max(ans, rptr-lptr);
++rptr;
}else{
++lptr;
}
}
return ans;
}

Don't Forget to like, comment, share and subscribe.

rapidcoders
Автор

any one explain from any eg. if we use (left_Min[left_S] <right_Max[right_S])in place of (left_Min[left_S] <= right_Max[right_S])

TodayContestSolution
Автор

its not a sliding window brother, its actually a 2 pointer approach

Priyanshukumar-ylnh