Back to problems

Find the Majority Element

Algorithm · Uber · Easy

Problem You are given an integer array nums containing n entries. Return the value that occurs more than n / 2 times. You can rely on the fact that such a value is present in every input. Function Signature Examples Input: nums = [4, 1, 4, 4, 2] Output: 4 Explanation: The value 4 appears 3 times in an array of length 5, so it occurs more than half the time. Input: nums = [7, 7, 3, 7] Output: 7 Explanation: There are 3 occurrences of 7 among 4 elements, making it the majority…

Checking your access…