Find Majority Element in an Array (Majority Element)

preview_player
Показать описание
Given an array of integers, find the majority element in an array. The majority element is the element that appears more than n/2 times (where n is the size of an array).

For example:

Input: {3,3,2,2,3,2,3}
Output: 3


Input: {1, 1, 4, 1, 4, 4, 1, 4, 4}
Output: 4

In this tutorial, I have explained a java code to find a majority element using HashMap.
Рекомендации по теме
Комментарии
Автор

Sir ! Why we are using getOrDefault method?

thorunitha
Автор

This wont work for array = { 3, 3, 7, 7, 10, 11, 11, 11, 11 }.. Pls let me know. ?

suneelsrikanta