#K8736. Maximum Consecutive Plants in the Same Season
Maximum Consecutive Plants in the Same Season
Maximum Consecutive Plants in the Same Season
You are given a list of plants where each plant is described by its species name and the season in which it grows. Your task is to determine the maximum number of consecutive plants in the list that grow in the same season. More formally, given an integer (n) and a list of (n) pairs ((\text{species}, \text{season})), find the maximum (k) such that there exists a contiguous segment of (k) plants having the same season.
For example, if the input is:
5
Rose spring
Tulip spring
Sunflower summer
Daisy spring
Lily spring
then the answer is 2 because the longest consecutive segment with identical season is either the first two plants or the last two plants that have the season 'spring'.
Note: If (n = 0), the answer is (0).
inputFormat
The input is given via standard input. The first line contains a single integer (n) representing the number of plants. Each of the next (n) lines contains two strings separated by space: the species name and the season (for example, 'spring', 'summer', 'winter', etc.).
outputFormat
Output a single integer which is the maximum number of consecutive plants that grow in the same season. The output should be printed to standard output.## sample
5
Rose spring
Tulip spring
Sunflower summer
Daisy spring
Lily spring
2