Last String Before It Becomes Empty Under Repeated Alphabetical Removals

Asked at Flexport · Coding Questions · Difficulty: Medium · Last asked Nov 6, 2026

A string of lowercase letters is shortened in rounds. In one round, go through the letters `a`, `b`, `c`, ..., `z` in that order, and for each letter that still occurs in the string, delete its first (leftmost) occurrence. Letters that do not occur are skipped. Rounds repeat until the string is empty. Return the string as it was at the start of the last round, which is the last non-empty string before the string became empty.

Loading the problem…