Victor travels around the world collecting coins. He is now in Surria and he would like to obtain at least one of each kind of Surrian coin. He is at a cash machine, and he only has time to make a single withdrawal before he has to leave. It is unknown how the machine determines which coins to return, so Victor must withdraw an amount that guarantees his goal.
You are given a int[] coins containing the values of each kind of Surrian coin. Note that multiple kinds of coins might actually have the same value, in which case, he still needs to get one of each kind (see example 3). Return the minimal sum that Victor must withdraw from the cash machine to receive at least one of each kind, or -1 if it is impossible. Assume that the machine carries an infinite supply of each kind of coin.
|