๐ WAYPOINT LESSON
Checkpoint โ The Profiled Pipeline
โญโญ intermediateโณ 28 min read๐ Lesson 149 of 265
Compose the module: batch a repeated lookup out of a loop, materialize a twice-run pipeline once, and prove the cheap path stays cheap โ all through counting fakes.
The gate (mini-build)
A tiny analytics service, cost-graded:
PriceBookโ built once fromint[] prices(sku i costsprices[i]). ExposesTotal(int[] skus)โ sum via a prebuilt array, no LINQ, no allocations per call โ andLookupCountrecording how many single-sku lookups callers performed throughLookup(int sku).TopSkus(int[] skus, int take)โ distinct skus by descending frequency, ties broken by smaller sku first, at mosttakeresults.Summary(int[] skus)โ built onTopSkus' materialized snapshot (one pass over the data), returning"{count}:{joined}"where count is the number of distinct skus and joined is comma-joined sku list.
public static class Solution
{
public sealed class PriceBook
{
public PriceBook(int[] prices);
public int Total(int[] skus); // no LINQ / no allocs per call
public int LookupCount { get; }
public int Lookup(int sku); // counted single-sku access
}
public static int[] TopSkus(int[] skus, int take);
public static string Summary(int[] skus);
}