# Can you help to solve this problem in C?

Problem Statement

Harry and Larry are now bored playing with numbers. Now they want to play with plus and minus signs. This time they don’t want to give signs one by one. Anyone can give any number of signs at a time but at most N signs. Can you tell the maximum of all signs that they gave sequentially?

For example:

• If the input is 7 + + - + - - - , then the answer is 3 as 3 minus signs are given sequentially and it is the maximum.
• If the input is 7 + + + + + - - , then the answer is 5.

Input Format

• First line will contain a positive integer N
• Second line will contain N signs (+ or -)

Constraints

1. 0 < N <= 100

Output Format

• Output a single integer, the maximum of all signs that came sequentially.

I tried with this solution but this seems to be wrong in some test cases:

``````#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{

int pcount = 1, mcount = 1, n, i;
char str[99];
scanf("%d", &n);
scanf("%s", str);

for( i = 0; i < n; i++){
if(str[i] == '+' && str[i + 1] == '+'){
pcount++;

} else if(str[i] == '-' && str[i + 1] == '-'){
mcount++;

}

}

if(mcount > pcount){
printf("%d", mcount);

} else if(pcount > mcount){
printf("%d", pcount);
} else {
printf("0");
}
return 0;
}
``````

Your code is giving correct input only when the longest sequence is at initial position, longest sequence can be anywhere in the string.
consider:
input:10 ++±++++++