279C. Ladder - Codeforces Solution C++

  Problem Link : 279C. Ladder 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

int main()
{
	int n,m;
	cin>>n>>m;
	ll arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	ll next[n],prev[n];
	next[n-1]=1;
	prev[0]=1;
	for(int i=n-2;i>=0;i--)
	{
		if(arr[i+1]>=arr[i])
			next[i]=next[i+1]+1;
		else
			next[i]=1;
	}

	for(int i=1;i<n;i++)
	{
		if(arr[i-1]>=arr[i])
			prev[i]=prev[i-1]+1;
		else
			prev[i]=1;
	}

	int l,r;

	while(m--)
	{
		cin>>l>>r;
		l--;
		r--;
		if(next[l]+prev[r] > r-l+1)
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!