All problems
0794MediumArrayHash TableCounting

Isolated Dock Numbers

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2150Find All Lonely Numbers in the 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 bike-share audit lists the dock every bike was returned to yesterday. The list docks holds one dock number per return, so a dock number appears once for each bike returned to it.

Docks are numbered so that dock d - 1 and dock d + 1 are the two docks standing either side of dock d. Call a dock number isolated when it appears exactly once in docks and neither d - 1 nor d + 1 appears in docks at all.

Return every isolated dock number, in ascending order. Return an empty list when there is none.

Examples

Example 1

Input
docks = [42, 7, 19, 20]
Output
[7, 42]

Dock 7 was used once and docks 6 and 8 are absent, and dock 42 was used once with 41 and 43 absent. Docks 19 and 20 stand beside each other and both appear, so neither qualifies.

Example 2

Input
docks = [5, 6, 10, 10, 3]
Output
[3]

Dock 3 was used once with 2 and 4 absent. Dock 10 was used twice, and docks 5 and 6 sit next to each other.

Example 3

Input
docks = [42, 42]
Output
[]

Dock 42 appears twice, so it is not isolated and nothing is reported.

Constraints

  • 1 <= docks.length <= 10^5
  • 0 <= docks[i] <= 10^6

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 isolated_docks(docks: list[int]) -> list[int]:
Java
public List<Integer> isolatedDocks(int[] docks)
September 7
Apply