Calculate Department Visit Difference for Shopping Lists
Asked at Karat · Coding Questions · Difficulty: Easy · Last asked Jul 15, 2026
Given a `String[][] products` representing each product and its corresponding department, such as `["Blueberries", "Produce"]` and `["Milk", "Dairy"]`. There is also a `String[] list` representing a shopping list. There are two ways to shop: one is to buy in order, which requires visiting `m` different departments; the other is to combine the same departments, only needing to visit `n` different departments. Calculate the difference between `m` and `n`.
Loading the problem…
More Karat interview questions
- Treasure Rooms Reachable from Any Room in DAG
- Find String Path in Grid Moving Only Right or Down
- Find Valid Rooms
- Bus Schedule Management with Priority Boarding
- Assign people to cars based on shortest travel time from two start points.
- Find Word with Anagram Present in Given String