Jolly Jumpers
InterviewTime limit1sMemory limit128 MB
For each sequence, check whether the absolute differences of adjacent elements are exactly the set 1 to n-1.
- Level
Easy3 of 10
- Topics
- Array, Hash map, Implementation, Math
- Solved
- No attempts yet
Problem
Determine whether an integer sequence is a Jolly jumper.
- A sequence of length is always a Jolly jumper.
- A sequence of length is a Jolly jumper if the absolute values of the differences between adjacent numbers include every integer from to exactly once. (There are exactly adjacent pairs.)
For example, the sequence 1 4 2 3 is a Jolly jumper because the absolute differences of its adjacent numbers are , which cover all of through .
Given several sequences, decide for each one whether it is a Jolly jumper.
Input
The input consists of several lines. Each line starts with the length () of a sequence, followed by integers separated by spaces. Lines are given until the end of input.
Output
For each sequence, print Jolly if it is a Jolly jumper and Not jolly otherwise, one result per line.