Skip to main content
๐Ÿ“œ 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:

  1. PriceBook โ€” built once from int[] prices (sku i costs prices[i]). Exposes Total(int[] skus) โ€” sum via a prebuilt array, no LINQ, no allocations per call โ€” and LookupCount recording how many single-sku lookups callers performed through Lookup(int sku).
  2. TopSkus(int[] skus, int take) โ€” distinct skus by descending frequency, ties broken by smaller sku first, at most take results.
  3. Summary(int[] skus) โ€” built on TopSkus' 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);
}