All problems
1140EasyArray

The Badge Filling Over a Quarter of the Roster

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1287Element Appearing More Than 25% In Sorted Array

This 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 roster roster of badge numbers is sorted in non-decreasing order. Exactly one badge number takes up more than a quarter of the entries.

Return that badge number.

Examples

Example 1

Input
roster = [1, 2, 2, 3, 3, 3, 3, 4]
Output
3

Eight entries mean a badge has to appear more than twice. Only 3 does, with four entries, while the two 2 entries are exactly a quarter and so fall short.

Example 2

Input
roster = [5, 5, 5, 5]
Output
5

Every entry carries the same badge, so it fills the whole roster.

Example 3

Input
roster = [1, 2, 3, 4, 4, 4]
Output
4

Six entries mean a badge needs at least two. Only 4 repeats at all, three times over.

Constraints

  • 1 <= roster.length <= 10^4
  • 0 <= roster[i] <= 10^5
  • roster is sorted in non-decreasing order
  • exactly one badge number takes up more than a quarter of the roster

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def find_special_integer(roster: list[int]) -> int:
Java
public int findSpecialInteger(int[] roster)
September 7
Apply