K3DEV-Editorial

K3DEV

Author: Dev Bhaskar Singh
Tester: Divyank Goyal
Editorialist: Dev Bhaskar Singh

DIFFICULTY:

Easy-Medium

PREREQUISITES:

Array,Two pointers

EXPLANATION:

This problem can easily be solved using two pointers technique.We will place the both pointers at the starting index int the array and keep on traversing and incrementing counter variable till we dont encounter the second number which is greater than k.now we will move the first counter to the previous number which is greater than k and keep on storing the largest gap between the indexes in the variable.At the end print the variable which is our required answer.

SOLUTIONS:

[details=“Setter’s Solution”]
[#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
void dev()
{
ll n=0,m=0,k=0,c=0,s=0,flag=0,x=0,y=0,z=0,t=0,d=0,e=0,f=0,g=0,h=0,i,j,l=0,maxi=-1,sum=0,sum1=0;
vectorv;
cin>>n>>k;
for(i=0;i<n;i++)
{
cin>>x;
v.pb(x);
}
j=0;
x=0;
for (i = 0; i < n; i++)
{
if (v[i] <= k)
c++;
if (v[i] > k)
{
if (x == 1)
{

            c = i - s ;
            x = 1;
        }
        else{
            x++;
            c++;
        }
        s = i;
    }
    maxi = max(maxi, c);
}
cout<<maxi<<"\n";

}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll num =1, i;
for (i = 1; i <= num; i++)
{
dev();
}
return 0;
}

]