BackmediumTwo Pointers

Majority Element Validator Solution

Problem Statement

Given an array of integers, determine if a majority element exists, which is defined as an element that appears more than n/2 times where n is the length of the array. A majority element must appear in more than half of the array's indices.

Example 1
Input
[3, 3, 4, 2, 3, 3, 2, 3, 3]
Output
true

Explanation: The element 3 appears 6 times, which exceeds half of the array length (n/2 = 4.5).

Example 2
Input
[1, 2, 3, 4, 5]
Output
false

Explanation: No element appears more than half of the array length (n/2 = 2.5 times).

Constraints

  • Array length is between 1 and 10^5 (inclusive).
  • Array contains only integers.
  • Time complexity should be achievable within O(n) for an optimal solution.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free