#K96267. Maximum Counter Value
Maximum Counter Value
Maximum Counter Value
You are given a sequence of operations on a counter. Initially, the counter is 0. Each operation is either a +
(increment) or a -
(decrement). Your task is to determine the maximum value the counter reaches during the sequence of operations.
More formally, let \(counter = 0\) initially. For each operation in the sequence, update the counter as follows:
[ \text{if operation is } +:\quad counter = counter + 1, \quad \text{if operation is } -:\quad counter = counter - 1 ]
Then, compute \(\max(counter)\) over all steps (including the initial value). Note that even if the counter becomes negative, the maximum value observed might still be positive.
inputFormat
The first line contains an integer \(N\) representing the number of operations. The second line contains \(N\) tokens separated by spaces, where each token is either +
or -
, representing an operation.
outputFormat
Output the maximum value of the counter achieved during the sequence of operations.
## sample5
+ - + + -
2
</p>