Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Implement Boyer Moore Majority Vote
00:00
5 left

Implement Boyer Moore Majority Vote

MediumPython

Problem

Give massive files with a list of N integers; how would you find an element that is seen N/2 + 1 times given that it always exists?

Implement the solution for a sequence of integers and return the integer occurring more than half the time. The sequence may be processed incrementally, so avoid storing frequency counts or requiring the entire input in memory.

Input: A non-empty iterable of integers. Output: The integer occurring at least N/2 + 1 times. The majority element is guaranteed to exist.

Constraints

  • 1 <= len(nums)
  • Each element is an integer
  • One element appears at least N/2 + 1 times
  • The input may be provided as a large iterable and should not require frequency storage

Function Signature

def find_majority_element(nums):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.