Elements Occurring More Than n/3 Times
Updated
Problem statement
Given an integer array nums of length n, return every distinct value whose frequency is strictly greater than n / 3.
Return qualifying values in increasing numerical order. Frequency counts occurrences of the whole integer value, rather than its individual decimal digits. Return an empty array if no value qualifies.
Function
majorityOverThird(nums: int[]) → int[]Examples
Example 1
nums = [3,2,3]return = [3]The value 3 occurs twice, strictly more than 3 / 3 = 1.
Example 2
nums = [1,2,1,2,1,2,3]return = [1,2]Both 1 and 2 occur three times, more than 7 / 3.
Example 3
nums = [1,2,3,4]return = []No frequency exceeds 4 / 3.
Constraints
0 <= nums.length <= 10^5-10^9 <= nums[i] <= 10^9- For integer frequencies, the threshold is equivalent to
frequency > floor(n / 3).
More Mygate Phone Screen questions
- Employees Earning More Than Their ManagerPHONE SCREEN · Seen Sep 2026
- Maximum Subarray SumPHONE SCREEN · Seen Sep 2026
- Reverse a Linked ListPHONE SCREEN · Seen Sep 2026
- Users Active in Both January and FebruaryPHONE SCREEN · Seen Sep 2026
- Frog Jump: Minimum EnergyPHONE SCREEN · Seen Jan 2025
- Left View of a Binary TreePHONE SCREEN · Seen Jan 2025
- Two SumPHONE SCREEN · Seen Aug 2024
- Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Jul 2024
- Minimum Subarray SumPHONE SCREEN · Seen Sep 2023
- Remove the Nth Node from the EndPHONE SCREEN · Seen Sep 2023
Similar questions at other companies
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsStripe · PHONE SCREENStripe interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- Insert Delete GetRandom O(1)Charta Health · PHONE SCREENCharta Health interview questions
- Longest Consecutive SequenceKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN