A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.

    A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].

Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.
int solution(int A[], int N) {
    // return 3 for [3,2,-5,1]
    int sum_prefix = 0;
    int sum_suffix = 0;
int i, j;
for (i = 0; i < N; i++) {
    // Check if is is the equilibrium point
    sum_prefix = 0;
    for (j = 0; j < i; j++) {
       sum_prefix += A[j];
    }
    sum_suffix = 0;
    for (j = i+1; j < N; j++) {
        sum_suffix += A[j];
       // Compute suffix sum
    }
    if (sum_prefix == sum_suffix)
        return i;
}
return -1;
}

leader of this array

A non-empty zero-indexed array A consisting of N integers is given. The leader of this array is the value that occurs in more than half of the elements of A.

  $A[0] = 1;
  $A[1] = 1;
  $A[2] = 1;
  $A[3] = 50;
  $A[4] = 1;

function solution($A){
  if(empty($A)) return -1;
  
  $array_total_element = count($A);
  $ar_cnt_values = array_count_values($A);

  foreach($ar_cnt_values as $value){
      if($value > $array_total_element/2) return 1;
    }
  return -1;
}