All problems
0940EasyArrayCounting

Is the Middle Reading One of a Kind

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3978Unique Middle Element

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.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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