AtCoder Beginner Contest 136 C. Build Stairs【Python】
https://atcoder.jp/contests/abc136/tasks/abc136_c
AtCoder ProblemsのRecommendationで Difficulty: 308、Solve Probability: 54%でした。
N = int(input()) H = list(map(int, input().split())) h1 = H[0] - 1 ch = 0 ph = h1 if N == 1: print('Yes') else: for i in range(1, len(H)): if i == 1: if h1 < H[i]: ch = H[i]-1 elif h1 > H[i]: print('No') exit() else: ch = H[i] ph = ch else: if ph < H[i]: ch = H[i]-1 elif ph > H[i]: print('No') exit() else: ch = H[i] ph = ch print('Yes')
かなり煩雑になってしまいました。解説にあるように後ろから判定していくというは思いつきませんでした。