➤ Problem Link : 1291B. Array Sharpening
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll arr[n+1];
ll inc[n+1];
ll desc[n+1];
for(int i=1;i<=n;i++)
cin>>arr[i];
if(n==1)
{
cout<<"Yes\n";
continue;
}
for(int i=0;i<=n;i++)
inc[i]=desc[i]=-1;
inc[1]=0;
for(ll i=2;i<=n;i++)
{
if(arr[i]>inc[i-1])
inc[i]=inc[i-1]+1;
else
break;
}
desc[n]=0;
for(ll i=n-1;i>=1;i--)
{
if(arr[i]>desc[i+1])
desc[i]=desc[i+1]+1;
else
break;
}
bool flag=0;
for(ll i=1;i<=n;i++)
{
if(inc[i]!=-1 && desc[i]!=-1)
{
flag=1;
break;
}
}
if(flag)
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!!
