Skip to content

Practice Shortest Impossible Sequence of Rolls

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2350
LeetCode Problem

Shortest Impossible Sequence of Rolls

Problem Statement

You are given an integer array rolls of length n and an integer k. You roll a k sided dice numbered from 1 to k, n times, where the result of the ith roll is rolls[i]. Return the length of the shortest sequence of rolls so that there's no such subsequence in rolls. A sequence of rolls of length len is the result of rolling a k sided dice len times.

Source: Shortest Impossible Sequence of Rolls on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
rolls = [4,2,1,2,3,3,2,4,1], k = 4
Output
3

# Example 2

Input
rolls = [1,1,2,2], k = 2
Output
2

# Example 3

Input
rolls = [1,1,3,2,2,2,3,3], k = 4
Output
1

Constraints

n == rolls.length
1 <= n <= 10^5
1 <= rolls[i] <= k <= 10^5

Related LeetCode Problems

Practice more problems similar to Shortest Impossible Sequence of Rolls.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.