Exercise 24 / 24: Slow Endpoint Shortlist
// Iterators of Code 2026 — Day 24: Slow Endpoint Shortlist
// Challenge: Compose one iterator pipeline, keeping only the set as state.
// Records are already slowest-first; do not sort. Skip cached records, then
// keep the first three distinct endpoint names in order. A cached occurrence
// must not prevent a later uncached occurrence of the same name from counting.
use std::collections::HashSet;
fn slow_endpoints<'a>(records: &[(&'a str, bool)]) -> Vec<&'a str> {
let mut seen = HashSet::new();
let mut names = Vec::new();
for &(name, cached) in records {
if cached {
continue;
}
if !seen.insert(name) {
continue;
}
names.push(name);
if names.len() == 3 {
break;
}
}
names
}
fn main() {
// Each pair is (endpoint name, served from cache).
let records = [
("/search", true),
("/checkout", false),
("/checkout", false),
("/search", false),
("/profile", true),
("/feed", false),
("/reports", false),
];
assert_eq!(
slow_endpoints(&records),
vec!["/checkout", "/search", "/feed"]
);
assert!(slow_endpoints(&[]).is_empty());
assert!(slow_endpoints(&[("/search", true)]).is_empty());
assert_eq!(
slow_endpoints(&[("/feed", false), ("/feed", false), ("/search", false)]),
vec!["/feed", "/search"]
);
}
Your solution
Standalone .rs / std only. Stored, not executed.
Editing access uses this browser's cookie. Clearing cookies loses access.