This question evaluates a candidate's competency in data manipulation and transformation, specifically pivoting tall datasets into wide views, handling missing metric values, ordering ISO date strings via string operations, and meeting algorithmic efficiency constraints (O(n log n)).
Transform a tall dataset into a wide, pivoted view without using any date/time libraries. Input: a list of records (date, store_id, metric, value) where date is an ISO 8601 string YYYY-MM-DD, metric ∈ {"sales", "refunds", "visits"}, and value is a non-negative integer. Output: for each (store_id, date), produce one row with columns [store_id, date, sales, refunds, visits], filling missing metric values with 0 and ordering rows by ascending date within each store. Requirements: (