Hard
Shortest Impossible Sequence of Rolls — Python
Full explanation · Time O(n) · Space O(k)
# Time: O(n)
# Space: O(k)
# constructive algorithms
class Solution(object):
def shortestSequence(self, rolls, k):
"""
:type rolls: List[int]
:type k: int
:rtype: int
"""
l = 0
lookup = set()
for x in rolls:
lookup.add(x)
if len(lookup) != k:
continue
lookup.clear()
l += 1
return l+1