Ultimate Jump Game
At the heart of the casino lies several tables of Ultimate Jump Game, a two-player twist on the classic LeetCode puzzle.
The game is played on an array of integers called the board. A jumper starts at index on the board, and the two players (you and the dealer) take turns moving it.
On your turn, you may move the jumper right by any positive number of squares no larger than the value on the square it currently occupies. For example, if the jumper is on a square showing , you may move it
,
, or
squares to the right.
Whoever moves the jumper onto the final square wins the game. The dealer always moves first. With optimal play, can you beat them?
Input
The first line contains a single integer
, the number of spaces on the board.
The second line contains integers
, representing values for each space of the board.
Output
For each test case, print "Yes" if you can beat the dealer with optimal play. Print "No" otherwise.
Example
Input 1
6
3 5 2 1 1 9
Output 1
No
The dealer is guaranteed to win, like so:
Game start:
3 5 2 1 1 9
^
The dealer moves the jumper 3 spaces:
3 5 2 1 1 9
^
You have to move the jumper 1 space:
3 5 2 1 1 9
^
The dealer moves the jumper 1 space, winning the game:
3 5 2 1 1 9
^
Input 2
7
3 5 2 3 1 1 9
Output 2
Yes
You can force a win.
Comments