DeepFrontend
Practice ArenaBlogSign in
Go Pro
DeepFrontend

Interview-grade learning paths and hands-on practice for mid-to-senior engineers. Master internals, patterns, and system architecture with runnable code.

All systems operational

Core Courses

  • -JavaScript Internals
  • -React Reconciliation
  • -TypeScript rigor
  • -Next.js Caching
  • -Node.js Event Loop
  • -System Design
  • -Web Security
  • -CSS & Page Layouts

Explore

  • Learning Paths
  • Practice Arena
  • Pricing Options
  • HTML Sitemap

Resources

  • Privacy Policy
  • Terms of Service
  • Email Support

© 2026 DeepFrontend. All rights reserved.

Expert learning environments for web engineering teams.

← All challenges
core12 min

Majority Element (Boyer-Moore)

Majority Element

Given an array nums where one element appears more than ⌊n/2⌋ times, return that element. A hash-map count works, but the elegant O(1)-space answer is the Boyer-Moore voting algorithm: keep a candidate and a count; matching votes increment, differing votes decrement, and a zero count adopts a new candidate.

majorityElement([3, 2, 3]);             // 3
majorityElement([2, 2, 1, 1, 1, 2, 2]); // 2

Run your code to see results.

Stuck? This challenge exercises:

javascript.data-structures