Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Majority Element

Python data engineering interview problem. Difficulty: beginner. Pattern: Hashing. About 10 minutes. Part of the Pro drill bank.

Find the element appearing more than n/2 times. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement majority_element(nums: list) -> int. Assume a majority always exists.

Constraints

  • A majority element is guaranteed.
  • n >= 1.

Examples

Input: majority_element([3, 2, 3]) Output: 3 3 appears twice of three.

Topics: lakebench, python, majority, voting.

More Python interview questions · All interview problems · Learn data engineering

beginner

Majority Element

Interview-style drill: Find the element appearing more than n/2 times.

Implement `majority_element(nums: list) -> int`. Assume a majority always exists. Example: `[3, 2, 3]` → `3`. Keep the harness.