FastPrepMajority Element
Problems/Majority Element

Majority Element

ByteDance logoByteDance● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: ByteDance asked this in the first of three phone screens for a security site-reliability engineering intern, after systems knowledge questions. The candidate named it by number and title as a well-known public problem: find the value that makes up more than half of an array.

The report gave nothing beyond that, so the problem follows the public version. Our choices here: at most 2 x 10^4 numbers (fewer than the public limit, to keep test files small), values from -10^9 to 10^9, and a majority value is always present.

Our version is about 95% the same as the reported question.

Given an integer array nums of length n, return its majority element: the value that appears more than n / 2 times.

The input always has a majority element.

Function

majorityElement(nums: int[]) → int

Examples

Example 1

nums = [3,2,3]return = 3
  • 3 appears 2 times out of 3, which is more than half.

Example 2

nums = [2,2,1,1,1,2,2]return = 2
  • 2 appears 4 times out of 7 and 1 only 3 times, so the answer is 2.

Example 3

nums = [7,1,7,2,7]return = 7
  • 7 appears 3 times out of 5. The first and last elements are not a reliable answer in general, but here both happen to be 7.

Constraints

  • n == nums.length
  • 1 <= n <= 2 × 104
  • -109 <= nums[i] <= 109
  • Some value appears more than n / 2 times in nums.

More ByteDance Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · Seen Nov 2026
  • Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
  • Longest Increasing SubsequencePHONE SCREEN · Seen Nov 2026
  • Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximum Number of Events That Can Be AttendedPHONE SCREEN · Seen Nov 2026
  • Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Meeting RoomsPHONE SCREEN · Seen Oct 2026
  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Shortest-Job-First Process SchedulingPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • Values Exclusive to the Current UserMeta · PHONE SCREENMeta interview questions
  • Count Values Appearing Exactly OnceAgoda · PHONE SCREENAgoda interview questions
  • Top Two Users by Total Purchase AmountSnowflake · PHONE SCREENSnowflake interview questions
  • Restaurant Vote LeadersZipRecruiter · PHONE SCREEN · ONSITE INTERVIEWZipRecruiter interview questions
  • AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions
  • Employees With Shared InterestsPalantir · PHONE SCREENPalantir interview questions

Interview reports that mention this question

  • ByteDance Security SRE Intern Phone Screens: 1 Experience

ByteDance interview experiences

  • ByteDance MLE New Grad Interviews: 1 Experience
  • ByteDance USDS New Grad SWE Phone Screen: 1 Experience
  • ByteDance New Grad Data Engineer Video Interviews: 1 Experience
  • ByteDance Trust & Safety Research Scientist Intern: 1 Experience
  • ByteDance ML Intern Phone Screen: 1 Experience
All ByteDance interview questionsSee ByteDance hiring insights
Saved
class Solution {
    public int majorityElement(int[] nums) {
        // Write your code here.
    }
}
Checking account…