Class Solution
- java.lang.Object
-
- g2301_2400.s2350_shortest_impossible_sequence_of_rolls.Solution
-
public class Solution extends Object
2350 - Shortest Impossible Sequence of Rolls.Hard
You are given an integer array
rollsof lengthnand an integerk. You roll aksided dice numbered from1tok,ntimes, where the result of theithroll isrolls[i].Return the length of the shortest sequence of rolls that cannot be taken from
rolls.A sequence of rolls of length
lenis the result of rolling aksided dicelentimes.Note that the sequence taken does not have to be consecutive as long as it is in order.
Example 1:
Input: rolls = [4,2,1,2,3,3,2,4,1], k = 4
Output: 3
Explanation: Every sequence of rolls of length 1, [1], [2], [3], [4], can be taken from rolls.
Every sequence of rolls of length 2, [1, 1], [1, 2], …, [4, 4], can be taken from rolls.
The sequence [1, 4, 2] cannot be taken from rolls, so we return 3.
Note that there are other sequences that cannot be taken from rolls.
Example 2:
Input: rolls = [1,1,2,2], k = 2
Output: 2
Explanation: Every sequence of rolls of length 1, [1], [2], can be taken from rolls.
The sequence [2, 1] cannot be taken from rolls, so we return 2.
Note that there are other sequences that cannot be taken from rolls but [2, 1] is the shortest.
Example 3:
Input: rolls = [1,1,3,2,2,2,3,3], k = 4
Output: 1
Explanation: The sequence [4] cannot be taken from rolls, so we return 1. Note that there are other sequences that cannot be taken from rolls but [4] is the shortest.
Constraints:
n == rolls.length1 <= n <= 1051 <= rolls[i] <= k <= 105
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intshortestSequence(int[] rolls, int k)
-