Problem:
 Score : 300 points    Problem Statement There are N squares arranged in a row from left to right. The height of the i -th square from the left is H_i .  For each square, you will perform either of the following operations once:   Decrease the height of the square by 1 .  Do nothing.   Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.      Constraints  All values in input are integers.  1 \leq N \leq 10^5  1 \leq H_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  H_1  H_2  ...  H_N       Output If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes ; otherwise, print No .        Sample Input 1 5
1 2 1 1 3      Sample Output 1 Yes  You can achieve the objective by decreasing the height of only the second square from the left by 1 .       Sample Input 2 4
1 3 2 1      Sample Output 2 No       Sample Input 3 5
1 2 3 4 5      Sample Output 3 Yes       Sample Input 4 1
1000000000      Sample Output 4 Yes

Solution (Python):
n = int(input())
h = [int(x) for x in input().split()]

lmax = h[0]
for i in range(1, n-1):
   lmax = max(lmax, h[i])
   if lmax - h[i+1] >= 2:
      print('No')
      exit()

print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1,1,-1):
    dif = h[i] - h[i-1]
    if(dif == -1):
        h[i-1] -= 1
    elif(dif < -1):
        print('No')
        exit()

print('Yes')

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
cnt = 0
if N == 1:
  pass
elif N==2:
  if h[0] <= h[1]:
    pass
  else:
    print('No')
    exit()
elif N >= 3:
  for i in range(N-2):
    if (h[i] - 1 == h[i+1]) and (cnt == 0):
      cnt += 1
    elif (h[i] < h[i+1]) and cnt == 1:
      cnt -= 1
    elif (h[i] - 1 == h[i+1]) and (cnt == 1):
      print('No')
      exit()
    if (h[i+1] > h[i+2]) and (h[i]-1 >= h[i+1]) :
      print('No')
      exit()
    elif (h[i] >= h[i+1]+2) or (h[i+1] >= h[i+2]+2):
      print('No')
      exit()
print('Yes')

Solution (Python):
n=int(input())
cnt,ans=0,0
h=list(map(int,input().split()))
h=h[::-1]
for i in range(n-1):
  if h[i]<h[i+1]:
    if abs(h[i]-h[i+1])>=2:
      print("No")
      exit()
    else:
      h[i+1]-=1
print("Yes")

Solution (Python):
n = int(input())
H = list(map(int, input().split()))

for i in range(n-1, 0, -1):
    if H[i-1] > H[i]:
        if H[i-1]-1 > H[i]:
            print('No')
            exit()
        else:
            H[i-1] += -1
print('Yes')

Solution (Python):

import numpy as np
N = int(input())
H = list(map(int, input().split()))
H = np.array(H)

ans = 'Yes'
for i in range(N-2, -1, -1):
    if (H[i] - H[i+1])>0:
        if (H[i] - H[i+1])==1:
            H[i] += -1
        else:
            ans='No'
            break
print(str(ans))

Solution (Python):
n = int(input())
H = list(map(int,input().split()))

for i in range(n-1):
  if H[i] == 1+ H[i+1]:
    H[i+1] += 1
  elif H[i] >1+ H[i+1]:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
for i in range(N-1):
    if H[i+1]-H[i]>0:
        H[i+1]-=1
    elif H[i+1]-H[i]==0:
        continue
    else:
        print("No")
        exit()
else:
    print("Yes")

Solution (Python):




def main():
    N = int(input())
    H = list(map(int, input().split()))

    for i in range(N - 1, 0, -1):
        if H[i - 1] <= H[i]:
            continue
        elif H[i - 1] - 1 == H[i]:
            H[i - 1] -= 1
        else:
            print('No')
            exit(0)

    print('Yes')


if __name__ == "__main__":
    main()

Solution (Python):





import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    h = list(map(int,ipti().split()))

    hmax = 0
    for i in range(n-1):
        if h[i] - 1 >= hmax:
            h[i] -= 1
        hmax = h[i]

    for i in range(1, n):
        if h[i] - h[i-1] < 0:
            print('No')
            sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
h =list(map(int,(input().split())))

cnt = 0
for i in h:
    if i >= 1 and i > cnt:
        cnt = i - 1
    elif i >= 1 and i == cnt:
        pass
    else:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
lst.reverse()

for i in range(n-1):
    if lst[i]+1 == lst[i+1]:
        lst[i+1] -= 1
    elif lst[i]+1 < lst[i+1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
base=0
for h in H:
    if base>h:
        print("No")
        break
    base=max(base,h-1)
else:
    print("Yes")

Solution (Python):
N=int(input())
H=list(map(int,input().split()))[::-1]
flag=True
base=H[0]
for i in range(N-1):
    if H[i]+1==H[i+1]:
        H[i+1]-=1
    elif H[i]>=H[i+1]:
        continue
    else:
        flag=False
print("Yes" if flag else "No")

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]

h2 = h[:]
can = True
for i in range(n-2, -1, -1):
    if h2[i] <= h2[i+1]:
        continue
    elif h2[i] > 1:
        h2[i] -= 1
    if not h2[i] <= h2[i+1]:
        can = False
        break

print('Yes') if can else print('No')

Solution (Python):
import sys

n = int(sys.stdin.readline())
h = list(map(int, sys.stdin.readline().split()))

ans = 'Yes'
h[0] -= 1
for i in range(n - 1):
    if h[i + 1] < h[i]:
        ans = 'No'
        break
    elif h[i + 1] > h[i]:
        h[i + 1] -= 1
print(ans)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
hmax=h[0]
for i in range(1,n):
    if h[i]<hmax-1:
        ans="No"
        break
    else:
        hmax=max(hmax,h[i])
print(ans)

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
flag=1
count=1
max=0
for i in range(N):
    if H[i]>max:
        max=H[i]
    if max-1>H[i]:
        flag=0
        break

if flag==0:
    print("No")
else:
    print("Yes")

Solution (Python):
N=int(input())
H=list(map(int,input().split()))

answer="Yes"

for i in range(1,N,):
    if H[N-i]>=H[N-i-1]:
        pass
    else:
        H[N-i-1]-=1
        if H[N-i]<H[N-i-1]:
            answer="No"

print(answer)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

for i in range(n-2, 0 , -1):
  if h[i] > h[i+1]:
    h[i] -= 1
    if h[i] > h[i+1]:
      print('No')
      break
else:
   print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
for i in range(0, N-1):
    if H[N-i-2]-1 == H[N-i-1]:
        H[N-i-2] = H[N-i-2]-1
    elif H[N-i-2]-1 > H[N-i-1]:
        print ("No")
        break
else:
    print ("Yes")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

flag = True
for i in range(n-1):
    if a[n-i-2] > a[n-i-1]:
        a[n-i-2]-= 1

    if a[n-i-2] > a[n-i-1]:
        flag = False
        break

print("Yes") if flag else print("No")

Solution (Python):
N = int(input())
H = [int(x) for x in input().split()]

ans = "Yes"
for i in range(1, N):
  if H[-(i + 1)] <= H[-i]:
    continue
  elif H[-(i + 1)] - 1 <= H[-i]:
    H[-(i + 1)] -= 1
  else:
    ans = "No"
    break
print(ans)

Solution (Python):
N = int(input())
H = list(map(int,input().split()))

for i in range (N-1):
    if H[i+1]+1 < H[i]:
        print("No")
        break
    elif H[i+1] < H[i]:
        H[i+1] += 1
else:
    print("Yes")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

last=h[0]-1
for now in h[1:]:
    if last > now:
        print("No")
        exit()
    elif last == now: 
        last = now
    else: 
        last = now-1
print("Yes")

Solution (Python):
import sys

input = sys.stdin.readline
_ = int(input())
nums = map(int, input().split())
maxnum = 0

for x in nums:
    if maxnum < x:
        maxnum = x
    if maxnum - x > 1:
        print('No')
        sys.exit() 

print('Yes')

Solution (Python):
import sys
N = int(input())
H = list(map(int, input().split()))

if N==1:
    print("Yes")
    sys.exit()
else:
    for i in range(N-1):
        if H[i] < H[i+1]:
            H[i+1] = (H[i+1] - 1)
        if H[i] > H[i+1]:
            print("No")
            sys.exit()  


print("Yes")

Solution (Python):
import sys

input = sys.stdin.readline
n = int(input())
nums = map(int, input().split())
maxnum = 0

for x in nums:
    if maxnum < x:
        maxnum = x
    if maxnum - x > 1:
        print('No')
        sys.exit() 

print('Yes')

Solution (Python):



def main():
  n = int(input())
  Hs = list(map(int, input().strip().split()))
  Hs[0] -= 1
  for i in range(n-1):
    if Hs[i] < Hs[i+1]:
      Hs[i+1] -= 1
    if Hs[i] > Hs[i+1]:
      print('No')
      return
  print('Yes')
      
  
if __name__=='__main__':
  main()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

ans = "Yes"
m = h[0]

for i in range(1, n):
    m = max(m, h[i])
    if h[i] < m - 1:
        ans = "No"

print(ans)

Solution (Python):

n = int(input())
h = [int(i) for i in input().split()]

flag = True
for i in reversed(range(n - 1)):
    if h[i] - h[i + 1] == 1:
        h[i] -= 1
    elif h[i] > h[i + 1]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):

n = int(input())
h = [int(i) for i in input().split()]

flag = True
for i in reversed(range(n - 1)):
    if h[i] - h[i + 1] == 1:
        h[i] -= 1
    elif h[i] > h[i + 1]:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
ls = list(map(int,input().split()))
i = 0
ls[0] -= 1
while i < N-1:
    if ls[i] < ls[i+1]:
        ls[i+1] -= 1
    if ls[i] > ls[i+1]:
        print("No")
        exit(0)
    i += 1
print("Yes")

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
flag = True
num = 0
for i in range(N-1):
  if H[i] - 1 == H[i+1] and H[i+1] >= num: 
    num = H[i+1]
  elif H[i] - 1 == H[i+1] and H[i+1] < num:
    flag = False
    break
  elif H[i] -1 > H[i+1]:
    flag = False
    break
if flag == True:
  print("Yes")
else:
  print("No")

Solution (Python):


n = int(input())
h = [int(i) for i in input().split()]

flag = 'Yes'
for i in reversed(range(n - 1)):
    if h[i+1] - h[i] < 0 and h[i+1] - h[i] >= -1:
        h[i] -= 1
    elif h[i+1] - h[i] <= -2:
        flag = 'No'
        break
print(flag)

Solution (Python):


n = int(input())
h = [int(i) for i in input().split()]

flag = 'Yes'
for i in reversed(range(n - 1)):
    if h[i+1] - h[i] < 0 and h[i+1] - h[i] > -2:
        h[i] -= 1
    elif h[i+1] - h[i] <= -2:
        flag = 'No'
        break
print(flag)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

maxi = 0
for i in range(N):
    if H[i] > maxi:
        maxi = H[i]
    elif H[i] < maxi:
        if maxi - H[i] > 1:
            print("No")
            break
else:
    print("Yes")

Solution (Python):
n=int(input())

t = list(map(int,input().split()))

for i in range(n-1, 0, -1):
    
    if t[i] < t[i-1]-1:
        print('No')
        exit()
    elif t[i] == t[i-1]-1:
        t[i-1] -= 1
print('Yes')

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
maxer = 1
for i in range(n):
    if h[i] > maxer:
        maxer = h[i]-1
    elif h[i] == maxer:
        pass
    else:
        print("No")
        exit()
print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
flag = True
for i in range(N-2, -1, -1):
    if H[i+1] < H[i] - 1:
        flag = False
        break
    elif H[i+1] == H[i] - 1:
        H[i] -= 1

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    H=LI()
    now = H[0]-1
    for h in H:
        if now>h:
            print("No")
            return
        if now == h:
            continue
        now = max(h-1,now)
    print("Yes")
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
m = 0
for k in range(1,N):
    if H[k-1] > H[k]+1 or H[k] < m:
        print("No")
        exit(0)
    elif H[k-1] == H[k]+1:
        m = H[k]
print("Yes")

Solution (Python):
import sys
stdin = sys.stdin
from itertools import accumulate

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
h = na()
hpre = h[-1]
for hi in h[:-1][::-1]:
    if hi <= hpre:
        hpre = hi
    elif hi == hpre + 1:
        hpre = hi - 1
    else:
        print("No")
        quit()
print("Yes")

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
M=[0]*N
count=0
while(1):
	count=0
	for i in range (N-1):
		if L[i]>L[i+1]:
			if M[i]==1:
				print("No")
				exit()
			else:
				L[i]-=1
				M[i]=1
		else:
			count+=1
	if count==(N-1):
		print("Yes")
		exit()

Solution (Python):


N = int(input())
H = list(map(int, str(input()).split()))

output = "Yes"
if N == 1:
    print(output)
    exit()

pre = -1
for i in range(N):
    if pre <= H[i] -1:
        pre = H[i] - 1
    elif pre <= H[i]:
        pre = H[i]
    else:
        output = "No"
        break

print(output)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h[0] -= 1
for i in range(1, n):
    if h[i]-h[i-1] < 0:
        print('No')
        exit()
    if h[i] - h[i-1] > 0:
        h[i] -= 1
print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

can = True

for i in range(1, n):
    if h[i] - h[i - 1] >= 1:
        h[i] -= 1
    elif h[i] == h[i - 1]:
        pass
    else:
        can &= False

print("Yes" if can else "No")

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if max(a) - min(a) <= 1:
  print("Yes")
  exit(0)
t = [0] * N
for i in range(N - 1):
  if a[i + 1] - a[i] < 0 and (t[i] == 0):
    a[i] -= 1
    t[i] = 1
  if a[i] - a[i + 1] < 0 and (t[i + 1] == 0):
    a[i + 1] -= 1
    t[i + 1] = 1

for i in range(N - 1):
  if a[i + 1] < a[i]:
    print("No")
    exit(0)
print("Yes")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    if i!=0:
        if a[i]>a[i-1]:
            a[i]-=1
    else:
        a[i]-=1
for i in range(n):
    if i!=n-1:
        if a[i]>a[i+1]:
            print('No')
            exit()
print('Yes')

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]

flag = False
for i in range(1,N):
    if H[i] - H[i-1] == 0:
        continue
    elif H[i] - H[i-1] < 0:
        flag = True
        break
    elif H[i] - H[i-1] > 0:
        H[i] -= 1

if flag:
    print("No")
else:
    print("Yes")

Solution (Python):
n, *a = map(int, open(0).read().split())

for i in range(n): a[i] -= a[0]

mx = cant = 0
for i in range(n):
    mx = max(mx, a[i])
    if a[i]<mx-1: cant = True
print("YNeos"[cant::2])

Solution (Python):
N = int(input())
H = [int(h) for h in input().split()]

ans = "Yes"
for i in range(1, N-1):
    if H[i] > H[i-1]:
        H[i] -= 1
    if H[i] > H[i+1]:
        ans = "No"
        break
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

A = [-10 ** 18] + A
ans = "Yes"

for i in range(N):
    if A[i] == A[i + 1]:
        continue
    elif A[i] + 1 <= A[i + 1]:
        A[i + 1] -= 1
    else:
        ans = "No"
        break

print(ans)

Solution (Python):
def main():
    N = int(input())
    H = [int(i) for i in input().split()]
    for i in range(N-1)[::-1]:
        if H[i] > H[i+1]:
            H[i] -= 1
            if H[i] > H[i+1]:
                return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
H = H[::-1]

for i in range(1, N):
    if H[i-1]<H[i]:
        H[i] -= 1
    
    if H[i-1]<H[i]:
        print('No')
        exit()
    
print('Yes')

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
for i in range(n-2,-1,-1):
    if a[i+1]<a[i]:
        a[i]-=1
for i in range(n-1):
    if a[i]>a[i+1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    H = [int(h) for h in input().split()]
    for i in reversed(range(N-1)):
        if H[i] > H[i + 1]: H[i] -= 1
        if H[i] > H[i + 1]: 
            print("No")
            break
    else: print("Yes")

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
H = list(map(int,input().split()))

mx = H[0]
for h in H[1:]:
    if h<mx-1:
        print('No')
        exit()
    mx = max(mx,h)
print('Yes')

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
for i in range(n-2,-1,-1):
    if h[i]>h[i+1]:
        h[i]-=1
for i in range(n-1):
    if h[i]>h[i+1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
h  = list(map(int, input().split()))
h = h[::-1]
for i in range(1, n):
    if h[i-1] < h[i]-1:
        print("No")
        exit()
    elif h[i] <= h[i-1]:
        pass
    else:
        h[i] -= 1
print("Yes")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
flag = True
for i in range(1, n-1):
    if h[n-i] - h[n-i-1] == -1:
        h[n-i-1] -= 1
    elif h[n-i] - h[n-i-1] < -1:
        flag = False
if flag:print("Yes")
else:print("No")

Solution (Python):
import sys

n, *H = map(int, sys.stdin.read().split())

def main():
    cur = 0
    for h in H:
        if h > cur:
            cur = h - 1
        elif h < cur:
            return 'No'
    return 'Yes'

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
n = int(input())
nums = [int(num) for num in input().split()]


def solve(nums):
    nums[0] -= 1
    for i in range(1, n):
        if nums[i] > nums[i-1]:
            nums[i] -= 1
            continue
        if nums[i] < nums[i-1]:
            return 'No'
    return 'Yes'


print(solve(nums))

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]

is_true = True
before_tmp = 1
for i in range(N - 1):
    
    tmp = H[i + 1] - H[i]
    if tmp < 0 and (tmp <= -2 or before_tmp <= -1):
        is_true = False
        break
    
    if tmp != 0:
        before_tmp = tmp

if is_true:
    print('Yes')

else:
    print('No')

Solution (Python):
n=int(input())
H=list(map(int,input().split()))
ans='Yes'
ma=0
for i in range(1,n):
    if ma-1>H[i]:
        ans='No'
        break
    ma=max(ma,H[i])
print(ans)

Solution (Python):
n=int(input())
h=list(map(int, input().split()))
c=0
if n!=1:
    for i in reversed(range(n-1)):
        if h[i]==h[i+1]+1:
            h[i]-=1
        elif h[i]-h[i+1]>=2:
            c=1
    if c==0:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Solution (Python):
N=int(input()) 
h=list(map(int,input().split())) 
cnt=1 
h[0]-=1 
if N==1: 
    print("Yes")
else:
    while cnt<=N-1:
        if h[cnt]-h[cnt-1]>=1:
            h[cnt]-=1
        elif h[cnt]-h[cnt-1]<0:
            print("No")
            break
        cnt+=1
        
    else:
        print("Yes")

Solution (Python):
N = int(input())
H = [int(x) for x in input().split()][::-1]
before = int(10e9) + 1
for h in H:
    if h >= before + 2:
        print('No')
        exit()
    before = min(before, h)
print('Yes')

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
h=h[::-1]
for i in range(n-1):
    if h[i+1]-h[i]>1: 
        print('No')
        exit()
    elif h[i+1]-h[i]==1:
        h[i+1] -= 1
    else:
        pass
print('Yes')

Solution (Python):
N = int(input())
H = [int(x) for x in input().split()][::-1]
before = int(10e9) + 1
for h in H:
    if h >= before + 2:
        print('No')
        exit()
    before = h if h <= before else h-1
print('Yes')

Solution (Python):
n = int(input())
height_lst = list(map(int,input().split()))
flag = True

if n==1:
    print('Yes')
else:
    if height_lst[0]==1:
        height1 = 1
    elif height_lst[0]>1:
        height1 = height_lst[0]-1

    for i in range(1,n):
        height = height_lst[i]
        if height==1:
            possible_lst = [1]
        elif height>1:
            possible_lst = [height-1,height]

        if max(possible_lst)<height1:
            flag = False
            break
        else:
            if min(possible_lst)>=height1:
                height1 = min(possible_lst)
            else:
                height1 = max(possible_lst)

    if flag:
        print('Yes')
    else:
        print('No')

Solution (Python):
n = int(input())
height_lst = list(map(int,input().split()))
flag = True

if n==1:
    print('Yes')
else:
    if height_lst[0]==1:
        height1 = 1
    elif height_lst[0]>1:
        height1 = height_lst[0]-1

    for i in range(1,n):
        height = height_lst[i]
        if height==1:
            possible_lst = [1]
        elif height>1:
            possible_lst = [height-1,height]

        if max(possible_lst)<height1:
            flag = False
            break
        else:
            if min(possible_lst)>=height1:
                height1 = min(possible_lst)
            else:
                height1 = max(possible_lst)

    if flag:
        print('Yes')
    else:
        print('No')

Solution (Python):
N = int(input())
H = list(map(int,input().split()))

if N == 1:
    print('Yes')
else:
    for i in range(N-1):
        if H[N-1-i] + 2 <= H[N-1-i-1]:
            print('No')
            break
        elif H[N-1-i] + 1 == H[N-1-i-1]:
            H[N-1-i-1] -= 1
        elif i == N-2 and H[0] <= H[1] + 1:
            print('Yes')

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
chk = True

for i in range(1,N):
    if A[i-1] == A[i]:
        continue
    elif A[i-1] < A[i]:
        A[i] -= 1
    else:
        chk = False
        
if chk:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
*h,=map(int,input().split())
h=h[::-1]
for i in range(n-1):
    if h[i]>=h[i+1]:
        continue
    else:
        h[i+1] -= 1
        if h[i] >= h[i+1]:
            continue
        else:
            print("No")
            exit(0)
print("Yes")

Solution (Python):
n = int(input())
H = list(map(int, input().split()))
ans = 'Yes'
ma = 0
for i in range(1,n):
    if ma-1 > H[i]:
        ans = 'No'
        break
    ma = max(ma, H[i])
print(ans)

Solution (Python):
N = int(input())
l = list(map(int, input().split()))
min_h = l[0]
is_possible = "Yes"
for i in range(N):
    if l[i] < min_h - 1:
        is_possible = "No"
        break
    min_h = max(min_h, l[i])

print(is_possible)

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
a=True
for i in range(N-1, 0, -1):
    if H[i-1]>H[i]:
        if H[i-1]-H[i]>1:
            a=False
            break
        else:
            H[i-1]-=1
print("Yes" if a else "No")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

ans = 'Yes'

if N > 1:
  H_rev = list(reversed(H))

  for i in range(N-1):
    if H_rev[i] < H_rev[i+1]:
      H_rev[i+1] -= 1

    if H_rev[i] < H_rev[i+1]:
      ans = 'No'
      break

print(ans)

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lh = rli()
    c = 0
    for h in lh:
        
        if h < c:
            print("No")
            return
        elif h == c:
            c = h
        else:
            c = h-1
    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
H = LIST()

for i in range(N - 1):
	if H[i] + 1 <= H[i + 1]:
		H[i + 1] -= 1
		continue

	if H[i] + 1 == H[i + 1]:
		continue
	if H[i] > H[i + 1]:
		print("No")
		exit()
	
print("Yes")

Solution (Python):
import sys
n = int(input())
h = list(map(int,input().split()))
mx = h[0]
for i in range(1,n):
    if h[i] < (mx-1):
        print("No")
        sys.exit()
    mx = max(mx,h[i])
print("Yes")

Solution (Python):
import sys

N = int(input())
H = list(map(int,input().split()))

for i in range(N-1):
    if H[i+1] == H[i]:
        None
    elif H[i+1] > H[i]:
        H[i+1] = H[i+1]-1
    else:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
ans='Yes'
maxm=max(0,h[0]-1)
for i in range(1,n):
    if h[i]<maxm: ans='No'; break
    maxm=max(maxm,max(0,h[i]-1))
print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

max=0
cnt=0
for i in range(N):
    if max-H[i]>=2:
        print('No')
        break
    else:
        cnt+=1
        if H[i]>max:
            max=H[i]
if cnt==N:
    print('Yes')

Solution (Python):
def main():
    n = int(input())
    h_list = list(map(int, input().split()))
    for i in range(n - 1)[::-1]:
        if h_list[i] == h_list[i + 1] + 1:
            h_list[i] = h_list[i] - 1
        elif h_list[i] > h_list[i + 1] + 1:
            print("No")
            return
    print("Yes")

main()

Solution (Python):
def main():
  import sys
  n=int(input())
  h=map(int,sys.stdin.readline().split())
  g=list(h)[::-1]
  j=g[0]
  for i in g:
    if i>j+1:
      print("No")
      exit()
    elif i==j+1:
      pass
    else:
      j=i
  print("Yes")
  
if __name__=="__main__":
  main()

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N=int(input())
    H=list(map(int,input().split()))
    s=0
    flag=0
    if N==1:
        flag=0
    else:
        for i in range(0,N-1):
            if H[i]>H[i+1]:
                s+=H[i]-H[i+1]
                if s>1:
                    flag=1
            elif H[i]<H[i+1]:
                s=0
    if flag==0:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
c = 0
for i in range(n - 1, 0, -1):
    if h[i - 1] == h[i] + 1:
        h[i - 1] -= 1
    if h[i - 1] > h[i] + 1:
        c = 1
        break
if c == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
H=list(map(int,input().split()))

for i in range(N):
    if i==0:
        continue
    if  H[i]<H[i-1]:
        print("No")
        exit()
    if H[i-1]<H[i]:
        H[i]-=1

print("Yes")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))


h[0] -= 1
for i in range(0, n-1):
    if h[i] <= h[i+1] -1:
        h[i+1] -= 1
    elif h[i] > h[i+1]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

memo = 0
for i in range(n-1):
  if h[i] > h[i+1]:
    memo = max(memo, h[i] - 1)
    if h[i] - h[i+1] > 2 or h[i+1] < memo:
      print("No")
      exit()
print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
h = H[-1]
ans = "Yes"
for i in range(N-1, -1, -1):
  if H[i] <= h+1:
    h = min(h, H[i])
  else:
    ans = "No"
    break
print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
h = H[-1]
ans = "Yes"
for i in range(N-1, -1, -1):
  if H[i] <= h+1:
    h = min(h, H[i])
  else:
    ans = "No"
    break
print(ans)

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
ans =  True
maxv = h[0]
for i in range(n-1):
        if h[i] > h[i+1]:
            if maxv-h[i+1] >= 2:
                ans = False
        elif maxv < h[i+1]:
            maxv = h[i+1]
if ans == True:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
pre = 0
for i in h:
    if i < pre:
        print('No')
        break
    elif i == pre:
        pre = i
    else:
        pre = i-1
else:
    print('Yes')

Solution (Python):


class Proc:
    def __init__(self):
        n = int(input().rstrip())
        self.stairs = [int(i) for i in input().rstrip().split(" ")]

    def get_ans(self):
        for i in range(len(self.stairs)):
            if i == 0:
                self.stairs[i] -= 1
            else:
                if self.stairs[i] < self.stairs[i - 1]:
                    return False
                elif self.stairs[i] > self.stairs[i - 1]:
                    self.stairs[i] -= 1
        return True


print("Yes" if Proc().get_ans() else "No")

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
M=[0]*N

while(1):
	count=0
	for i in range (N-1):
		if H[i]>H[i+1]:
			if M[i]==1:
				print("No")
				exit()
			else:
				M[i]=1
				H[i]=H[i]-1
		else:
			count+=1
	if count==N-1:
		print("Yes")
		exit()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    H=LI()
    now = 0
    for h in H:
        if now > h:
            print("No")
            return
        now = max(now, h-1)
    print("Yes")
if __name__ == '__main__':
    main()