FastPrepFastPrep
Problem Brief

Bakery Quality Control

INTERNOA

Your program controls boxes of pastries coming out of a bakery. For each produced box, you are required to compare its contents to a list of expected items (its "template") and determine whether the box is correct or not. The contents of a box is described by a string such as "pcm" for 'p'ie, 'c'ookie, and 'm'uffin, or "ddp" for 'd'onut, 'd'onut, and 'p'ie. The template is described in the same manner. So given a list of (box, template) pairs, your program should indicate how many times it found a mismatch between a box and its template and return that total.

A box contains no more than 10 items, and there are no more than 1000 boxes to check at a time. Items in a box can be repeated, so "cc" (cookie cookie) is not the same as "c" (cookie). Items are not ordered, so the box "cm" (cookie, muffin) matches the template "mc" (muffin, cookie).

Function Description

Complete the function countMismatchedBoxes in the editor.

countMismatchedBoxes has the following parameters:

  1. 1. String[] boxes: an array of strings representing the contents of each box
  2. 2. String[] templates: an array of strings representing the expected contents of each box

Returns

int: the number of boxes that do not match their templates

1Example 1

Input
boxes = [["cm", "mc"], ["ccm", "mc"], ["pm", "mc"], ["c", "mc"]], templates = ["mc", "mc", "mc", "mc"]
Output
3
Explanation
The pair ["cm", "mc"] is valid; the order of items in the box doesn't matter. The pair ["ccm", "mc"] is invalid; there are too many cookies in the box. The pair ["pm", "mc"] is invalid; there is a pie in the box, and no cookie. The pair ["c", "mc"] is invalid; there is a muffin missing in the box. Given that list, your program should return 3, as it found 3 invalid boxes out of 4.
public int countMismatchedBoxes(String[][] boxes) {
  // write your code here
}
Input

boxes

[["cm", "mc"], ["ccm", "mc"], ["pm", "mc"], ["c", "mc"]]

templates

["mc", "mc", "mc", "mc"]

Output

3

Sign in to submit your solution.