Consider an array A. Your job is to find longest subarray in which elements greater than x are more than elements not greater than x
Input
1. size of array , x
2. Array elements
Example
Input
5 5
4 5 7 8 3
Output
3
Explanation
Subarray formed : [5,7,8]
please share more examples for this problem
j=list(map(int,input().split(” “)))[0:2]
n=j[0]
e=j[1]
l=list(map(int,input().split(” “)))[0:n]
k=[]
for i in l:
if(i>=e):
k.append(i)
print(len(k))
It is wrong answer
#checkout this one
n,k=map(int,input().split())
l=list(map(int,input().split()))
subarray=[l[i:j] for i in range(n) for j in range(i+1,n+1) if l[i]>=5]
res=0
for i in subarray:
for j in i:
if j<k:break;
else:
if res<len(i):res=len(i)
print(res)
It is a dp problem
#include
using namespace std;
int main(){
int n,x;
cin>>n>>x;
int a[n];
for(int i=0; i>a[i];
int max=0;
int maxCurr=0;
for(int i=0; i<n; i++){
if(a[i]<x)
maxCurr=0;
maxCurr++;
if(max<maxCurr)
max=maxCurr;
}
cout<<max;
return 0;
}
n = int(input(“enter the value of n: “))
x = int(input(“enter the value of x: “))
array = list(map(int, input(“Enter a array: “).split()))
new_array = []
for i in range(n):
if array[i] <= x:
new_array.append(array[i])
print(len(new_array))
n,k=map(int,input().split())
l=list(map(int,input().split()))
arr=[]
i=0
for i in range(0,len(l)):
j=len(l)-1
while i != j:
arr.append(l[i:j])
j=j-1
for i in arr:
if len(i) >= len(l)/2:
a = all(number >=k for number in i)
if a:
print(i)