Enter your book access code

The curriculum, drills, tutor, and interviewer mode are for readers of Ace the Rust Interview. The code is printed in the Preface (Companion site access).

Don’t have the book yet? The landing page stays open — purchase unlocks this gym.

intermediate · order 74

Range sums via prefix array

arr-prefix-01Related book chapters: 15 (optional — this page is complete on its own)prefix-sum

Slug: arr-prefix-01 · Paired reading: Chapter 15

Prompt

Build struct Prefix(Vec<i64>) with fn new(a: &[i64]) -> Self and fn range_sum(&self, lo: usize, hi: usize) -> i64 summing a[lo..hi] (half-open) in O(1) after O(n) preprocess.