Trains the technique from
LeetCode 229Majority Element IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A stockroom keeps a ledger of manual corrections. entries[i] is the signed size of the i-th correction, negative when stock was written off and positive when stock was added back.
An auditor wants the correction sizes that dominate the ledger: every value that appears strictly more than n / 3 times, where n is the number of entries and the division is truncated toward zero. In other words, a value qualifies when its number of occurrences is greater than floor(n / 3).
Return the qualifying values sorted in ascending order. Return an empty list when no value qualifies. Solve it in O(n) time using only O(1) extra space beyond the list you return.
Example 1
There are 6 entries, so a value needs more than floor(6 / 3) = 2 occurrences. The value 4 appears 3 times and qualifies; -1 appears twice and 2 appears once, so neither does.
Example 2
With 4 entries a value needs more than floor(4 / 3) = 1 occurrence. Both 7 and 3 appear twice, and the answer lists them in ascending order.
Example 3
With 9 entries a value needs more than floor(9 / 3) = 3 occurrences. The value 0 appears exactly 3 times, which is not strictly more than 3, and every other value appears once.
Example 4
One entry means a value needs more than floor(1 / 3) = 0 occurrences, and -6 appears once.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def frequent_adjustments(entries: list[int]) -> list[int]:public List<Integer> frequentAdjustments(int[] entries)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.