quest

Sign in to start training

quest keeps your progress, streaks, and scores tied to your account — so you can pick up on any device.

Synced everywhere. Progress follows you across laptop and phone.
Streaks & stats. See your daily run and every score over time.
Your profile. A name and avatar for the work you do here.

We only use Google to sign you in and sync progress. No posting, no contacts — ever.

Core Advanced

11  Lifetimes

When a function or struct hands out a reference, the compiler needs to know how long it stays valid. Add the annotations that make these compile.

Step 1 / 2

Add lifetimes so longest compiles and returns the longer &str.

Hints
  • Tie inputs and output together: fn longest<'a>(x: &'a str, y: &'a str) -> &'a str.
11_lifetimes.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() >= y.len() { x } else { y }
}