Back to problems

Elements Appearing More Than n/3 in a Sorted Array

Algorithm · ByteDance · Medium

Requirements You receive a sorted array nums containing at least three elements. Return every distinct value whose count is greater than len(nums) / 3. Follow-up: exploit the sorted ordering to achieve a runtime below O(n). Examples In the first and fourth arrays, no number occurs more than one third of the array length. In the second array, 3 appears twice, which is greater than 5 / 3. In the third array, both 2 and 7 occur twice, exceeding 5 / 3. Preparation Work through…

Checking your access…