#K48362. Count Initial Upright Planks
Count Initial Upright Planks
Count Initial Upright Planks
You are given a number n representing the total number of planks arranged in a line, and a sequence of n integers where each integer represents the state of a plank (1
for upright and 0
for flat). Your task is to count the number of consecutive upright planks starting from the beginning of the line until you encounter the first flat plank.
Note: As soon as a flat plank is encountered, the counting stops.
Input Format: The input consists of two lines. The first line contains the integer n (\(1 \leq n \leq 10^5\)). The second line contains n space-separated integers where each integer is either \(0\) or \(1\).
Output Format: Output a single integer which is the count of consecutive upright planks from the start.
For example, if n = 5 and the sequence is 1 1 0 1 1
, the answer is 2
because counting stops at the first 0
.
inputFormat
The first line contains a single integer n — the number of planks. The second line contains n space-separated integers (each either 0 or 1) representing the state of each plank.
outputFormat
Output a single integer — the number of consecutive upright planks starting from the beginning until the first flat plank is encountered.## sample
5
1 1 0 1 1
2
</p>