Core Beginner

05  Collections

Work with the two collections you'll reach for most: find a maximum safely, then tally word frequencies.

Step 1 / 2

Return the largest element, or None if empty, in max.

Hints
  • Iterator has a built-in max(), and it already returns an Option.
  • A slice's iter() yields &i32; .copied() turns them into i32.
05_collections.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
fn max(v: &[i32]) -> Option<i32> {
    v.iter().copied().max()
}