Skip to content

Practice Majority Element II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#229
LeetCode Problem

Majority Element II

Problem Statement

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Example 1: Example 2: Example 3: Constraints: Follow up: Could you solve the problem in linear time and in O(1) space?

Source: Majority Element II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

Input
nums = [1]
Output
[1]

# Example 3

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

Constraints

1 <= nums.length <= 5 * 10^4
-10^9 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Majority Element II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.