← 返回 bytedance 的题目列表Find Elements Appearing More Than One Third in a Sorted Array
类型:online_judge
Problem: Find Elements Appearing More Than One Third in a Sorted Array
Given an integer array nums sorted in non-decreasing order, with length n >= 3.
Find all numbers whose frequency is strictly greater than n / 3, and return them in ascending order.
Requirements
Basic requirement: implement a correct algorithm.
Follow-up: use the fact that the array is sorted and achieve time complexity better than O(n).
Input Format
The first line contains an integer n, the length of the array.
The second line contains n integers sorted in non-decreasing order.
Output Format
Output the result in Python list format, for example [1, 4].
If no such number exists, output [].
Constraints
3 <= n <= 10^5
-10^9 <= nums[i] <= 10^9
nums is sorted in non-decreasing order.
Example 1
Input:
3
1 2 3
Output:
[]
Example 2
Input:
5
1 1 2 3 4
Output:
[1]
Example 3
Input:
5
1 1 2 4 4
Output:
[1, 4]
Example
Input
3
1 2 3
Output
[]