Google Online Assessment (OA) - Pick Up Coupons

You are given a scratchcard consists of a row of non-negative integers. To win the scratch game, you need to scratch at least 2 numbers of the same value. You can only scratch consecutive numbers from the card. Scratching each number costs 1 dollar. Return the minimum cost to win the game, or -1 if winning is not possible.

Examples

Example 1:

Input:

[1, 3, 4, 2, 3, 4, 5]

Output: 4
Explanation:

You can scratch either [3, 4, 2, 3] or [4, 2, 3, 4].

Example 2:

Input:

[2, 5, 0, 3, 7]

Output: -1
Explanation:

There are no numbers of the same value.

Try it yourself

Solution

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]
  3

Get premium for instant access to all content and solutions

Upgrade