Majority Element Problem Statement

Given an array/list 'ARR' consisting of 'N' integers, your task is to find the majority element in the array. If there is no majority element present, return -1.

Example:

Input:
T = 2
N = 3
ARR = [3, 3, 4]
N = 5
ARR = [1, 1, 2, 2, 2]
Output:
3
2
Explanation:

For the first test case, majority element is 3 as it appears more than floor(3/2) = 1 times. For the second, 2 is the majority element as it appears more than floor(5/2) = 2 times.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 5 * 103
  • -105 <= ARR[i] <= 105

Time limit: 1 sec

Note:

A majority element is an element that occurs more than floor(N / 2) times in the array. The output is managed by the system; you only need to implement the function to find the majority element.

AnswerBot
4mo

Find the majority element in an array, return -1 if no majority element exists.

  • Iterate through the array and keep track of the count of each element using a hashmap.

  • Check if any element's count is gre...read more

Help your peers!
Select
Add answer anonymously...
Smart Energy Water Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits