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.


Example 1:


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

Output: 4

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

Example 2:


[2, 5, 0, 3, 7]

Output: -1

There are no numbers of the same value.

Try it yourself




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.

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

Get premium for instant access to all content and solutions