← 返回 atlassian 的题目列表Shopping Category Trip Difference
类型:qbank
Given product-to-category mappings and a shopping list, compare category transitions under different shopping-trip orderings. The prompt asks for the difference in trip counts between the original order and a grouped-by-category order.
Requirements
Input includes product-category pairs such as milk -> dairy and carrot -> produce.
Input includes a shopping list containing products.
Count category runs/trips in the given shopping order.
Compare against an ordering that groups products by category.
Return the difference between the original trip count and the grouped trip count.
Examples
product categories:
milk -> dairy
carrot -> produce
egg -> dairy
cabbage -> produce
shopping list: {milk, carrot, cabbage, egg}
Trip 1: milk (dairy) -> carrot, cabbage (produce) -> egg (dairy) = 3
Trip 2: milk, egg (dairy) -> carrot, cabbage (produce) = 2
return Diff = 1
Notes
Clarify whether the shopping list is ordered despite being written with braces in the prompt. The example relies on the given order.
Clarify how to handle unknown products or products with multiple categories.
Preparation
Implement run counting over the original list.
Implement the grouped baseline as the number of distinct categories present, then compare the two counts.