Problem · Array

Maximum Satisfied Customers

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem statement

Each customer lists every item they need, and each shop lists the items it stocks. You may open at most two shops.

A customer is satisfied when every required item is stocked by at least one open shop. Return the maximum number of customers that can be satisfied simultaneously.

Function

maxSatisfiedCustomers(customers: int[][], shops: int[][]) → int

Examples

Example 1

customers = [[1,2],[1,5]]shops = [[1,3,4,5],[2,4,6,8],[1,3,4,6]]return = 2

Opening the first and second shops makes items 1, 2, and 5 available, satisfying both customers.

Constraints

  • 1 <= customers.length <= 200
  • 1 <= shops.length <= 60
  • 1 <= customers[i].length, shops[j].length <= 20
  • 1 <= item <= 10^9
  • Repeated item identifiers in one list have the same meaning as one occurrence.

More Atlassian problems

drafts saved locally
public int maxSatisfiedCustomers(int[][] customers, int[][] shops) {
  // Write your code here.
}
customers[[1,2],[1,5]]
shops[[1,3,4,5],[2,4,6,8],[1,3,4,6]]
expected2
checking account