FFORGE//RS
← Roadmap

rust / LEVEL 3

The window that moved backward

EST.35 MIN
01

THEORY / RETRIEVAL

What to restore

  • Maintain the last-seen invariant for a sliding window
  • Keep the left boundary monotonic after repeated characters
  • Distinguish UTF-8 bytes from Unicode scalar values in Rust

A window compresses repeated work

For each right endpoint, remember the next position after the last occurrence of its character. The valid left boundary is the maximum of its current value and that remembered position, so it never moves backward. Each character enters once, giving linear time.

Define what length means

Rust strings are UTF-8 and cannot be indexed by arbitrary byte offset. This exercise counts Unicode scalar values through `chars()`. User-perceived grapheme clusters are a different contract and require dedicated segmentation support.

CHECKPOINT

When the current character was last seen before the current window's left boundary, how should left change?

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / IMPLEMENTATION

Implement the contract

Return the length in Unicode scalar values of the longest substring with no repeated character. The solution must be linear in the number of chars and must not slice the UTF-8 string by char indices.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
1 / 64 KB
OUTPUT
Runner is waiting for a submission.