Counter for warehouse zone visits
Python data engineering interview problem. Difficulty: beginner. Pattern: Dictionaries. About 10 minutes. Free to practice.
Forklifts scan a warehouse zone each time they enter it. A heatmap needs how many visits each zone received.
A warehouse records which zone a worker visited, one entry per visit. Managers want to see the busiest zones first. Count how many times each zone appears. Return a list of (zone, count) pairs, sorted by count from high to low, and by zone name (A to Z) when counts are equal. Write zone_visit_counts(zones). For ['A','B','A','C','B','A'] the result is [('A', 3), ('B', 2), ('C', 1)]. An empty list gives []. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Count each zone.
- Return (zone, count) pairs.
- Sort by count descending.
- Break ties by zone name ascending.
Constraints
- zones is a list of strings.
- The result is a list of tuples.
Examples
Input: zone_visit_counts(['A', 'B', 'A', 'C', 'B', 'A']) Output: [('A', 3), ('B', 2), ('C', 1)] This input follows the stated rules and produces this output.
Topics: lakebench, python, dictionaries.
More Python interview questions · All interview problems · Learn data engineering
Counter for warehouse zone visits
Interview-style drill: Given a sequence of warehouse zone visits, return each zone's visit count sorted by frequency.
Count visits per warehouse zone.