Cute Ryan
InterviewTime limit1sMemory limit256 MB
Given a row of N dolls labeled 1 or 2, find the length of the shortest contiguous block containing at least K dolls labeled 1.
- Level
Medium5 of 10
- Topics
- Two pointers, Sliding window, Array, Prefix sum
- Solved
- No attempts yet
Problem
dolls are placed in a row. Each doll is either a Ryan doll or an Apeach doll. A Ryan doll is written as 1 and an Apeach doll as 2. Find the length of the shortest contiguous block of dolls that contains at least Ryan dolls.
Input
The first line contains and . ()
The second line contains space-separated integers describing the dolls. Each value is 1 or 2.
Output
Print the length of the shortest contiguous block that contains at least Ryan dolls. If no such block exists, print -1.