Problem: 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.

Submission attempts (in order):
import sys

N = int(input())
h_list = list(map(int, input().split()))
# print(N, h_list)

flag = True

#     for j in range(i+1, N):
#         if (h_list[i]- h_list[j]) > 1:

#             break
#     if not flag:
#         break

max_v = max(h_list)
left_max_index = h_list.index(max(h_list))
print(left_max_index)

min_v = min(h_list)
right_min_index = [i for i, v in enumerate(h_list) if v == min(h_list)][-1]
print(right_min_index)

if left_max_index < right_min_index:
    if (max_v - min_v) > 1:
        print("No")
        sys.exit(0)

for i in range(0, N-1):
    i_v = h_list[i]
    min_v = min(h_list[i+1:N])

    if i_v - min_v > 1:
        flag = False
        break


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


N = int(input())                                                                                                                                                                                                                                                                
h_list = list(map(int, input().split()))                                                                                                                                                                                                                                        
# print(N, h_list)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                
flag = True                                                                                                                                                                                                                                                                     
for i in reversed(range(1, N)):                                                                                                                                                                                                                                                 
    diff = h_list[i-1]- h_list[i]                                                                                                                                                                                                                                               
#    print(i, diff)                                                                                                                                                                                                                                                             
    if diff >= 2:                                                                                                                                                                                                                                                               
        flag = False                                                                                                                                                                                                                                                            
        break                                                                                                                                                                                                                                                                   
    elif diff == 1:                                                                                                                                                                                                                                                             
        h_list[i-1] -= 1                                                                                                                                                                                                                                                        
    else:                                                                                                                                                                                                                                                                       
        pass                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                
if flag:                                                                                                                                                                                                                                                                        
    print("Yes")                                                                                                                                                                                                                                                                
else:                                                                                                                                                                                                                                                                           
    print("No")  

Verdicts: Wrong Answer

Accepted