Get the majority element from a given array of integers containing duplicates
// check whether `A[i]` is a majority element or not
for (int i = 0; i <= n/2; i++)
{
int count = 1;
for (int j = i + 1; j < n; j++)
{
if (A[j] == A[i]) {
count++;
}
}
if (count > n/2) {
return A[i];
}
}
return -1;