Statistics

Problem Statement for "Mailbox"

Problem Statement

We are going to sell a collection of individual plastic characters that customers will buy and place on their mailboxes to spell out their addresses. We have a String[] of "typical" addresses and want to be able to compare a proposed collection to these addresses and determine how many are impossible to form from our collection.

We will count an address as impossible if it cannot be formed from our entire collection of characters. Space characters in an address can always be formed because the customer can form spaces by placing our plastic characters as he wishes.

Create a class Mailbox that contains a method impossible that is given a String collection and a String[] address and that returns the number of elements in address that are impossible to form from the given collection of characters.

Definition

Class:
Mailbox
Method:
impossible
Parameters:
String, String[]
Returns:
int
Method signature:
int impossible(String collection, String[] address)
(be sure your method is public)

Constraints

  • collection will contain between 1 and 50 characters inclusive
  • Each character in collection will be an uppercase letter 'A'-'Z' or a digit '0'-'9'.
  • address will contain between 1 and 50 elements inclusive.
  • Each element of address will contain between 1 and 50 characters inclusive.
  • Each character in each element of address will be an uppercase letter 'A'-'Z' or a digit '0'-'9' or a space ' '.

Examples

  1. "AAAAAAABBCCCCCDDDEEE123456789"

    {"123C","123A","123 ADA"}

    Returns: 0

    All these can be formed. The space in "123 ADA" can never be a problem, and collection contains two 'A's. We only consider one address at a time so it doesn't matter that we cannot form both "123C" and "123A" at the same time from this collection.

  2. "ABCDEFGHIJKLMNOPRSTUVWXYZ1234567890"

    {"2 FIRST ST"," 31 QUINCE ST", "606 BAKER"}

    Returns: 3

    We cannot form any of these. The first address requires two 'S's, the second address requires a 'Q', and the third address requires two '6's.

  3. "ABCDAAST"

    {"111 A ST", "A BAD ST", "B BAD ST"}

    Returns: 2

    "111 A ST" cannot be formed since collection does not contain any digits. "B BAD ST" cannot be formed because it requires 2 'B's.

  4. "Z"

    {"ZZ","Z Z"," Z"," Z ","Z AVE"}

    Returns: 3

  5. "ABCDEFGHIJKLMNOPQRSTUVWXYZ112233"

    {"HARVARD ST"," HARP ST ","1231 TURNER", "12341 TURNER"}

    Returns: 3

  6. "1111111111111111111111111"

    {"1111111111111111111111111","11 111111111111111111 11","1"}

    Returns: 0

  7. "ABCABCABC"

    {" BABA ","CACACA", "CACACA","ABACBBACC"}

    Returns: 0

  8. "ABCABCABC"

    {" BABA ","CACACA", "CACACA","ABACBBACCC"}

    Returns: 1

  9. "ABCDEFGHIJKLMNOP"

    {"POG FIJ KALM","BAD FOG JIM","B"}

    Returns: 0

  10. "ABBCCCDDDDEEEEF"

    {"A B B B","CACDCEC","FEED FEED"}

    Returns: 3

  11. "ZYXWVUTSRQPONMLKIJHGFEDCBA12345"

    {"A","B","C","D","E","F","G","H","IJK","L","M","NO","P","QRA","ST A", "A","B","C","D","E","F","G","H","IJK","L","M","NO","P","QRA","ST A", "1 2 3","6","FED","AB POK","CAB"}

    Returns: 1

  12. "HOOP"

    {" PO HOP "}

    Returns: 1

  13. "HOOP"

    {" PO HO "}

    Returns: 0

  14. "D"

    {" "," D","D "," D "," "}

    Returns: 0

  15. "ABBCCCDDDDEE"

    {"BAD ADD", "DEED CAB C C DCD","BADCA"}

    Returns: 3

  16. "ABCDEFGHIJKLMNOPRSTUVWXYZ1234567890"

    { "2 FIRST ST", " 31 QUINCE ST", "606 BAKER" }

    Returns: 3

  17. "S"

    { "S", "S", "S", "S", "S", "S" }

    Returns: 0

  18. "AD"

    { "AAAADDDD" }

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: