Find Longest Negative Number Sequence Sum

Given an array of numbers, you are expected to return the sum of the longest sequence of negative numbers in the array. If there are no negative numbers in the array. You are expected to return -1.
In this question’s scope, the number 0 should be considered as positive.
Note: If there are more than one group of elements in the array having the longest sequence of negative numbers, you are expected to return the total sum of all of those negative numbers.

Function Description
Implement function SumOfLongestNegativeNumberSequence()
Parameters
  • int input1: represents the number of elements in the array
  • int input2[]: represents the array of integers
Return
Return an integer
Sample Input1
15
-13 -15 13 19 18 14 -5 11 -13 32 -5 -1 -77 78 -79
Sample output1
-83
Sample Input2
13
22 25 7 9 0 21 16 26 18 94 62 14 100
Sample output2
-1
Sample Input3
16
31 -33 -25 -97 13 18 -13 -15 -17 7 4 32 -9 -7 78 -79
Sample output3
-200
Solution in C JAVA PYTHON
#include<stdio.h>
int SumOfLongestNegativeNumberSequence(int, int*);
int main() {
  int n,arr[50];
  int result;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }
  result = SumOfLongestNegativeNumberSequence(n, arr);
  printf("%d",result);
  return 0;
}

int SumOfLongestNegativeNumberSequence(int input1,int* input2){
  int len=0, maxlen=0, sum=0, total=-1;
  for(int i=0;i<input1;i++){
    if(input2[i]<0){
      len++;
      sum+=input2[i];
    }else{
      if(maxlen<len){
        maxlen=len;
        total=sum;
      }else if(maxlen==len){
        total+=sum;
      }
      len=0;
      sum=0;
    }
  }
  if(maxlen<len){
    total=sum;
  }else if(maxlen==len){
    total+=sum;
  }
  return total;
}