UVa 10038

From Algorithmist
Jump to navigation Jump to search

10038 - Jolly Jumpers[edit]

Summary[edit]

Determine if the absolute values of the difference between successive elements take on all the values 1 through n-1.

Explanation[edit]

  1. Create a set
  2. For each number, calculate the absolute difference between it and its predecessor and add the difference to the set
  3. If the size of the set is n-1, output "Jolly"

Gotcha's[edit]

  • The size of the input (3000) is on the large-ish size
  • Make sure the differences are all between 1 and n-1

Input[edit]

4 1 4 2 3
5 1 4 2 -1 6

Output[edit]

Jolly
Not jolly

Solutions[edit]