#K12021. Minimize Missing Books

    ID: 23598 Type: Default 1000ms 256MiB

Minimize Missing Books

Minimize Missing Books

You are given an integer n representing the number of books and a list of n integers where each integer represents a book. A value of 0 indicates that a book is missing. Your task is to rearrange or loan back books such that the largest continuous segment of missing books is minimized. In fact, you only need to return the length of the longest contiguous sequence of missing books.

The challenge can be mathematically described as finding:

$$L = \max_{1 \leq i \leq n} (\text{length of consecutive zeros at position } i) $$

Example: For an input of n=5 and list [1, 0, 3, 0, 5], the longest contiguous missing books segment is 1, hence the output is 1.

inputFormat

The input is provided via standard input (stdin) and consists of two lines. The first line contains a single integer n indicating the number of books. The second line contains n space-separated integers representing the books. Each integer is either non-zero (present book) or zero (missing book).

Example:

5
1 0 3 0 5

outputFormat

The output is a single integer printed to standard output (stdout) representing the length of the longest contiguous segment of missing books.

Example:

1
## sample
5
1 0 3 0 5
1

</p>