Show problems as
Classic problem #3978EasyArrayCounting

Unique Middle Element

Real-world version: Is the Middle Reading One of a Kind
Tracked in this browser only
Read Unique Middle Element on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Readings are given as nums, and there is an odd number of them, so exactly one sits in the middle.

Return true when that middle reading appears nowhere else in the list.

Examples

Example 1

Input
nums = [4, 9, 27, 9, 4]
Output
true

The middle reading is 27, which appears nowhere else.

Example 2

Input
nums = [1, 2, 1]
Output
true

The middle reading is 2 and it is the only 2 on the list, even though the reading 1 is repeated.

Example 3

Input
nums = [8, 8, 3, 8, 8]
Output
true

The middle reading is 3, on its own, so the four eights around it make no difference.

Constraints

  • 1 <= nums.length <= 100
  • nums.length is odd
  • 1 <= nums[i] <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def is_middle_element_unique(nums: list[int]) -> bool:
Java
public boolean isMiddleElementUnique(int[] nums)