Check If a Number Is Majority Element in a Sorted Array
A easy-tier problem at 59% community acceptance, tagged with Array, Binary Search. Reported in interviews at Salesforce and 0 others.
You're solving a problem that looks trivial but trips up half the candidates who see it. Check If a Number Is Majority Element in a Sorted Array is an Easy problem, yet the acceptance rate sits at 59%, which signals careless mistakes rather than hard math. Salesforce asks this. The premise is simple: given a sorted array and a target number, determine if it's a majority element (appears more than n/2 times). The trap is thinking you need a hash map or linear scan when the array is sorted and you've got Binary Search at your disposal. StealthCoder solves it in seconds if you blank on the optimal pattern during your live assessment.
Companies that ask "Check If a Number Is Majority Element in a Sorted Array"
Check If a Number Is Majority Element in a Sorted Array is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe obvious route is to count occurrences in a single pass or use a frequency map. Both work, but they're overkill and waste the sorted guarantee. The intended solution uses Binary Search to find the leftmost and rightmost positions of the target, then check if the span exceeds n/2. Many candidates either skip binary search entirely, implement it incorrectly (off-by-one errors on range boundaries), or forget to validate that the element actually is the majority before returning true. The sorted property is the entire hint. If you're in an OA and realize mid-attempt that your linear approach won't scale or passes some test cases but fails others, StealthCoder runs invisibly and surfaces the two-binary-search template that works every time. Topics here are Array and Binary Search, both core to systems interviews.
Pattern tags
You know the problem.
Make sure you actually pass it.
Check If a Number Is Majority Element in a Sorted Array recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Check If a Number Is Majority Element in a Sorted Array interview FAQ
Why is acceptance only 59% if this is marked Easy?+
Off-by-one bugs in binary search boundaries and mishandling the range check (forgetting to verify count > n/2) are the main culprits. The problem itself is conceptually simple, but implementation sloppiness kills half the submissions. Code careful boundaries.
Can I just do a linear scan to count occurrences?+
Yes, it passes, but it's not the intended pattern. Given a sorted array, examiners expect you to recognize the binary search opportunity. Linear scan is O(n); binary search is O(log n). In an OA, the interviewer or system will note you missed the optimization hint.
How do I correctly implement the binary search bounds check?+
Find the leftmost index where target appears, find the rightmost index, then verify (rightmost - leftmost + 1) > n/2. Use standard binary search templates for 'find first' and 'find last' to avoid boundary errors. Test your lo/hi/mid updates carefully.
Does Salesforce specifically ask this problem in their OA?+
Salesforce is listed as one company that has asked it. They're testing basic array manipulation and binary search fluency. Expect it to appear as a warm-up or filter question, not the hardest on their loop.
What if the target isn't in the array at all?+
Binary search will return invalid bounds (lo past hi or no valid range). Your rightmost - leftmost + 1 will be zero or negative, failing the majority check. Handle it naturally; don't special-case. A clean solution handles absence for free.
Want the actual problem statement? View "Check If a Number Is Majority Element in a Sorted Array" on LeetCode →