All problems
0035EasyHash TableStringQueueCounting

First Solo Stop

Tracked in this browser only
Write code

Trains the technique from

LeetCode 387First Unique Character in a String

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 courier's shift is written down as the string route. Each position holds one lowercase letter naming the loading bay that was visited at that point in the shift, and a bay can be visited more than once.

A bay is solo when it shows up exactly once in the whole shift. Return the position of the earliest solo bay in route, counting positions from 0. If every bay in the shift was visited two or more times, return -1.

Examples

Example 1

Input
route = "swiss"
Output
1

Bay s is visited three times, so the earliest bay visited once is w at position 1.

Example 2

Input
route = "kayak"
Output
2

Bays k and a are each visited twice, leaving y at position 2 as the only solo bay.

Example 3

Input
route = "gg"
Output
-1

The single bay in this shift is visited twice, so no solo bay exists.

Constraints

  • 1 <= route.length <= 10^5
  • route contains lowercase English letters only

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 first_solo_stop(route: str) -> int:
Java
public int firstSoloStop(String route)
September 7
Apply