Skip to interview prep
Apexed

Find the majority element (appearing more than n/2 times) in O(n) time and O(1) space. How do you merely check whether a given element is the majority?

Content review

Report an error

Not yet reviewed

Data structures & algorithms277 of 395

MediumSearching & selection

Technical

This is ungraded practice. Run your solution and compare it with the model answer. Your drafts are saved in this browser.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Press Run to see your program’s output.

Find the majority element (appearing more than n/2 times) in O(n) time and O(1) space. How do you merely check whether a given element is the majority — Data st