Average Temperature
InterviewTime limit1sMemory limit1024 MB
Given a string of N plus and minus signs, find the length of the longest contiguous stretch with equal counts of each.
- Level
Easy3 of 10
- Topics
- Prefix sum, Hash map
- Solved
- No attempts yet
Problem

This winter Vytautas decided to harden himself. He wants to train in both warm and cold weather, and he wants to keep doing it for as long as possible without a break. Before making his training schedule, Vytautas checked the weather forecast. For each of the next N days he marked whether the day would be warm or cold. He marked warm days with plus signs and cold days with minus signs.
Given the sequence of plus and minus signs that describes the forecast, find the longest interval in which there are equal numbers of warm and cold days.
Input
The first line contains the number of days N.
The second line contains a string of N characters made of + (a warm day) and - (a cold day).
Output
Print one integer: the length of the longest interval that contains equal numbers of + and -.