Majority Element

Easy · Arrays & Hashing · Array · Hash Table · Divide and Conquer

Problem

One value in nums appears more than len(nums) // 2 times. Return it. You may assume such a value always exists.

Examples

Input: nums = [3,2,3]
Output: 3

3 appears twice out of three.

Input: nums = [2,2,1,1,1,2,2]
Output: 2

2 appears four times out of seven.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…