One-Step Stack

Here you need to check whether the values in a stack form a clean increasing chain. Given stack, where the bottom is on the left and the top is on the right, return True if each next element is exactly 1 greater than the previous one. If this order breaks even once, return False.

Примеры

Ввод
[3, 4, 5, 6, 7]
Вывод
True
Ввод
[3, 4, 6, 7]
Вывод
False
Ввод
[3, 2, 1]
Вывод
False

Нужно реализовать

def is_consecutive(stack: list[int]) -> bool:

Теги

stack
PostgreSQLv16

Aici va apărea rezultatul execuției codului

Visible tests
1
Input
[3,4,5,6,7]
ExpectedTrue
2
Input
[3,4,6,7]
ExpectedFalse
3
Input
[3,2,1]
ExpectedFalse
4
Input
[5]
ExpectedTrue
5
Input
[3]
ExpectedTrue
6
Input
[]
ExpectedTrue
Focus radio
Paused · SomaFM · Fluid