In a Stackline analytics mock, decide which catalog scope a sales rank belongs to before comparing it across days. Two retailers can report the same SKU identifier while applying a different category definition.
What to prepare for Stackline
Stackline describes retail and shopper analytics products. Its careers page provides role context. The exercises are original preparation for a software role working with retail analytical data. Stackline Atlas retail analytics Stackline careers
Rank entries within one retailer and period
Input rows give item identity, retailer, period and units. Sum units by item for a selected retailer and period, then return the top k by descending units and ascending item ID as tie-breaker. Multiple partial stores may contribute rows to one item.
from collections import Counter
def top(rows, retailer, period, k):
counts = Counter()
for item, shop, day, units in rows:
if (shop, day) == (retailer, period):
counts[item] += units
return sorted(counts.items(), key=lambda pair: (-pair[1], pair[0]))[:k]
assert top([('b', 'a', 1, 2), ('c', 'a', 1, 2), ('a', 'b', 1, 99)], 'a', 1, 1) == [('b', 2)]
assert top([('b', 'a', 1, 2), ('b', 'a', 1, 3)], 'a', 1, 2) == [('b', 5)]
Counting uses O(n) time. Ranking uses O(g log g) for g grouped items and can be reduced to O(g log k) when only a small k is needed. Before combining rows, distinguish genuinely distinct stores from a duplicated import.
A follow-up to work through
If retailer A and retailer B disagree on what belongs in a category, a rank change can simply reflect a taxonomy version. Keep catalog version beside each generated rank. Compare old and new versions against a fixed sample before making an alert for changed rank.
def comparable(left, right):
return all((left.get(key) == right.get(key) for key in ('retailer', 'taxonomy', 'period_type')))
assert comparable({'retailer': 'x', 'taxonomy': 1, 'period_type': 'week'}, {'retailer': 'x', 'taxonomy': 1, 'period_type': 'week'})
assert not comparable({'taxonomy': 1}, {'taxonomy': 2})
What to bring to a mock interview
Bring a project where an aggregate metric moved after the underlying catalog, category or attribution rule changed. Include the before/after grain and a saved input fixture.