FFORGE//RS
← Roadmap

rust / LEVEL 2

The view that must not outlive its source

EST.30 MIN
01

THEORY / RETRIEVAL

What to restore

  • Express the relationship between input and output lifetimes
  • Return a view into a collection without allocating

Lifetimes describe relationships

A lifetime parameter does not extend how long a value lives. It tells the compiler which input borrow constrains an output borrow. Returning `&'static str` is only valid when the data itself is static; it is not a shortcut for difficult annotations.

Tie handling is part of the contract

Iterator adapters can hide subtle behavior such as which equal maximum wins. Interview code should make allocation, tie-breaking and empty-input behavior explicit instead of relying on an accidental implementation detail.

CHECKPOINT

Which signature can return either input while guaranteeing that the result never outlives the selected borrow?

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / IMPLEMENTATION

Implement the contract

Implement `longest_nonempty` without allocation. Return the first value when byte lengths tie, ignore empty strings, and keep the public signature unchanged.

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