Fewest Page Turns
In a book, you can flip pages from the front or from the back, so the shortest direction matters. The function drawing_book receives the total number of pages n and the target page p. Return the minimum number of page turns needed to reach page p.
Примеры
Ввод
6, 2Вывод
1Ввод
5, 4Вывод
0Ввод
6, 1Вывод
0Нужно реализовать
def drawing_book(n: int, p: int) -> int:
Теги
math
Log in om je inzendingsgeschiedenis te zien
InloggenLog in om de AI-mentor te gebruiken
InloggenVisible tests
1
Input
6, 2Expected
12
Input
5, 4Expected
03
Input
6, 1Expected
04
Input
6, 6Expected
05
Input
7, 4Expected
16
Input
6, -6Expected
-3Focus radio
Paused · SomaFM · Fluid