FastPrepMinimum Stores for a Shopping List
Problems/Minimum Stores for a Shopping List

Minimum Stores for a Shopping List

WhatNot logoWhatNot● HardFULLTIMENEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report asks for the minimum number of stores needed to cover a shopping list. The finite item bound and impossible-case result make that set-cover capability deterministic for practice.

You have a shopping list and a collection of stores. Each store carries a set of items. Return the minimum number of distinct stores you must visit so that every item on the shopping list can be purchased.

An item may be purchased from any visited store that carries it. Duplicate names in the shopping list represent the same required item. Return -1 when at least one required item cannot be covered.

Function

minimumStores(stores: String[][], shoppingList: String[]) → int

Examples

Example 1

stores = [["milk","bread"],["eggs"],["bread","eggs"]]shoppingList = ["milk","eggs"]return = 2

No single store carries both required items, so two visits are necessary.

Example 2

stores = [["apple","tea"],["tea","rice","apple"],["rice"]]shoppingList = ["apple","rice","tea"]return = 1

The second store covers the entire list.

Example 3

stores = [["a"],["b"]]shoppingList = ["a","c"]return = -1

No store carries c.

Constraints

  • 0 <= stores.length <= 50.
  • 0 <= shoppingList.length <= 20.
  • Every item name is a non-empty case-sensitive ASCII string of length at most 40.
  • Repeated item names within a store do not change its coverage.

More WhatNot problems

  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Adjacent Pair and Run RemovalPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public int minimumStores(String[][] stores, String[] shoppingList) {
        // Write your solution here.
    }
}
Checking account…