Skip to main content
LeetCode 229, Medium. Topics: Array, Hash Table, Sorting, Counting. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 15 parametrized pytest cases, and a playground notebook:

Problem

Given an integer array of size n, find all elements that appear more than ⌊n / 3⌋ times.

Examples

Constraints

  • 1 <= nums.length <= 5 * 10^4
  • -10^9 <= nums[i] <= 10^9
Follow up: Could you solve the problem in linear time and in O(1) space?

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode 250, NeetCode All.
Last modified on August 25, 2026