Statistics

Problem Statement for "DessertMaker"

Problem Statement

You have a number of tasty ingredients and you want to know how many different banana split desserts you could make using those ingredients. In order for something to count as a banana split, it must have at least one "banana", at least one "ice cream", and at least one other ingredient (i.e., at least one ingredient that is not a "banana" or an "ice cream"). Ingredients with the same name are not distinguishable, and it doesn't matter what order the items are added to the dessert. For example, suppose you had the following 5 ingredients:
  • "ice cream","banana","chocolate","chocolate","peanuts"
You could make a total of 5 different banana splits, as shown below:
  • "ice cream","banana","chocolate","chocolate","peanuts"
  • "ice cream","banana","chocolate","peanuts"
  • "ice cream","banana","chocolate","chocolate"
  • "ice cream","banana","chocolate"
  • "ice cream","banana","peanuts"
Note that if you would have had 2 bananas, you would have had 10 possibilities - as adding a banana to each combination above makes a new dessert. Return the number of distinct banana splits you could create using the items given in ingredients.

Definition

Class:
DessertMaker
Method:
countBananaSplits
Parameters:
String[]
Returns:
int
Method signature:
int countBananaSplits(String[] ingredients)
(be sure your method is public)

Constraints

  • ingredients will contain between 1 and 30 elements, inclusive.
  • Each element of ingredients will contain between 1 and 50 characters, inclusive.
  • Each element of ingredients will contain only lowercase letters and spaces ('a'-'z',' ').

Examples

  1. {"ice cream","banana","chocolate","chocolate","peanuts"}

    Returns: 5

    The example from the problem statement.

  2. {"banana", "banana", "chocolate", "strawberries", "pineapple", "pineapple", "rice cream"}

    Returns: 0

    To make a banana split, you need "ice cream", "banana", and at least one other ingredient. We have a "banana" and plenty of other ingredients, but we don't have an "ice cream" so we have zero possibilities.

  3. {"ice cream", "ice cream", "banana", "banana", "chocolate", "chocolate"}

    Returns: 8

    To see the 8 possibilities, note that you can pick either one or two "ice cream"s, one or two "banana"s and one or two "chocolate"s (and 2*2*2=8). You cannot have no ice cream or no bananas - and we need to have at least one other ingredient so we need at least one chocolate. Note that {"ice cream","banana","chocolate"} counts as a different dessert than {"ice cream","ice cream","banana","banana","chocolate","chocolate"} because the ingredient list is not identical.

  4. {"foam", "apple", "whipped cream", "apple", "mushroom", "apple core", "ice cream", "ice cream", "banana", "giraffe", "mushroom", "spare tire", "ice cream", "banana", "foam", "wrench", "paper", "cherry", "alarm clock", "football" ,"apple", "apple"}

    Returns: 138234

    You don't know if it'll be good until you try it.

  5. {"ice cream","banana", "a","a","a","a","a","a","a","a","a","a", "a","a","a","a","a","a","a","a","a","a", "a","a","a","a","a","a","a","a"}

    Returns: 28

  6. {"ice cream","banana", "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","aa","bb"}

    Returns: 268435455

    The maximum answer.

  7. {" ice cream","ice cream ","ice cream","ice cream ","banana","banana","ice cream"," "}

    Returns: 60

  8. {"banana","i c e c r e a m","icecream","ice cream","r","s","t","l","n","e"," "," "," ","ice cream"}

    Returns: 4095

  9. {"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij","abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij","abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij", "abcdefghijabcdefghijabcdefghij"}

    Returns: 0

  10. {"oyjvd", "banana", "wfknj", "banana"}

    Returns: 0

  11. {"ice cream", "ice cream", "omymc", "ice cream", "glwdd"}

    Returns: 0

  12. {"ice cream", "banana", "banana", "ice cream", "sjyua", "sjyua", "imrgp", "banana", "rgknb", "ice cream", "ice cream", "banana", "ice cream", "fcnnx"}

    Returns: 460

  13. {"ice cream", "pzbzp"}

    Returns: 0

  14. {"ice cream", "banana", "ice cream", "cnddf", "misvv", "banana", "ice cream", "ice cream", "banana", "ice cream", "vdvlt", "zsile", "misvv", "banana", "ice cream", "xxcob", "banana", "ice cream", "cnddf", "xxcob", "mfmya"}

    Returns: 7525

  15. {"banana", "ice cream", "ice cream", "ygnky", "ecmnq", "iohgn", "banana", "iohgn", "bzqer", "zrlxr", "iohgn", "pvizq", "ice cream"}

    Returns: 762

  16. {"banana", "idmjj", "ice cream", "banana", "banana", "ice cream", "banana", "ice cream", "wyprp", "zanre", "iddoi", "mjqkk", "tnkon", "ice cream", "wyprp", "iddoi", "ice cream", "ice cream", "ice cream", "sppxj", "vjrnc", "banana", "ice cream", "zanre", "banana"}

    Returns: 41424

  17. {"wttsl", "ice cream", "banana", "xnlkj", "banana", "ice cream", "banana", "arywl", "banana", "xnlkj", "ice cream", "crvzx", "ice cream", "fxgkr", "kroul", "banana", "banana", "banana", "banana", "xnlkj", "vusrs", "ice cream", "banana", "vaqjw", "banana", "ice cream"}

    Returns: 30660

  18. {"ice cream", "ice cream", "ice cream", "qpfqj", "banana", "ice cream", "banana", "zhhwx", "banana", "banana", "wzvbn", "banana", "rqgta", "plztj", "rqgta", "zhhwx", "errrj", "cjtak", "ice cream", "opfbd", "nyyed", "ice cream", "jxagh", "banana", "banana", "wzvbn", "cjtak", "rqgta", "banana"}

    Returns: 331728

  19. {"ngwja", "banana", "banana", "banana", "ysbvj", "banana", "banana", "banana", "fsirm", "fsirm", "kvxds", "ice cream", "ice cream", "banana", "banana"}

    Returns: 368

  20. {"ice cream", "xyjki", "banana", "ohwyb", "banana", "banana", "ice cream", "banana", "banana", "nugyp", "xhsgz", "banana", "nfibu"}

    Returns: 372

  21. {"banana", "nkesk", "ice cream", "ajysc", "wzbxj", "ice cream", "mopjo", "banana", "ajysc", "ice cream", "banana", "ice cream", "banana", "eowck", "ice cream", "qmrbg", "ice cream", "ice cream", "ice cream", "qmrbg", "mopjo", "ice cream", "galvh", "ice cream", "ice cream", "nkesk", "ajysc", "ice cream", "ajysc", "banana"}

    Returns: 64740

  22. {"vixqf", "banana", "banana", "jxnpw", "wydfg", "banana", "ice cream", "ice cream", "eoshe", "ice cream", "jlhxo", "ice cream", "jxnpw", "jlhxo", "ice cream", "eoshe", "gtzxm", "banana", "vixqf", "banana", "banana", "banana", "banana"}

    Returns: 12920

  23. {"ice cream", "ice cream", "banana", "iazbt", "ice cream", "wvvuv", "wzccl", "banana", "banana", "banana", "wzccl", "banana", "banana", "wvvuv", "banana", "psuzr", "banana", "ice cream", "tqkpb", "lketl", "ice cream", "xkugx", "ice cream", "ice cream", "wsrnj"}

    Returns: 32200

  24. {"banana", "banana", "lyswb", "ice cream", "banana", "abmov", "muowh", "snlwp", "rnspy"}

    Returns: 93

  25. {"ice cream", "banana", "ice cream", "ydihq", "enujh", "skqye", "jwcce", "ice cream", "gfbpn", "ice cream", "banana", "hdkes", "banana", "banana", "dqddr", "ice cream", "hdkes", "ice cream", "ice cream", "enujh", "ice cream", "ice cream", "gfbpn", "ice cream", "banana", "ice cream", "fgvcz", "banana", "xdwyo"}

    Returns: 113982

  26. {"bkhkb", "ice cream", "mxzal", "banana", "ndqjt", "duins", "ice cream", "ice cream", "ice cream", "banana", "banana", "zvbqp", "banana", "mxzal", "zvbqp", "pwcxy", "pwcxy", "ice cream", "fpbva", "ice cream", "gqyll", "zvbqp", "ojhyt", "ojhyt", "ojhyt"}

    Returns: 110568

  27. {"etxbk", "fwoov", "banana", "whezc", "banana", "kusqt"}

    Returns: 0

  28. {"ice cream", "banana", "fcwxv", "banana", "ice cream", "ice cream"}

    Returns: 6

  29. {"ice cream", "ujmyh", "ice cream", "qnjlh"}

    Returns: 0

  30. {"ice cream", "ice cream", "banana", "ice cream", "swqjb", "reqaf", "slqfc", "banana", "xqsej", "banana", "ice cream", "ice cream", "eozsy", "banana", "ice cream", "banana", "xqsej", "banana", "banana", "reqaf", "ice cream", "oskdz", "banana", "banana", "ice cream", "banana", "banana", "fklnk", "ice cream"}

    Returns: 28413

  31. {"ice cream", "czzzs", "ice cream", "topqd", "sfgvq", "qjdyi", "banana", "ice cream", "banana", "banana", "banana", "ice cream", "hxjeb", "dsggk", "ice cream", "ixfwr", "ice cream", "oitdl", "qjdyi", "banana", "ice cream", "banana", "ice cream", "ixfwr"}

    Returns: 27600

  32. {"gnduh", "glfar", "ice cream", "wwebl", "banana", "ice cream", "xgpkw", "banana", "wwebl", "fkoup", "banana", "xswea", "ice cream", "xgpkw", "fkoup", "ice cream", "ice cream", "dutsf", "xswea", "wwebl", "yinpq", "banana", "ice cream", "yinpq", "ice cream"}

    Returns: 72548

  33. {"cfath", "ice cream", "kxaod", "ice cream", "rnell", "ice cream", "ice cream", "ice cream", "ice cream", "banana", "ice cream", "mizvl", "vwcrf", "banana", "banana", "banana"}

    Returns: 868

  34. {"banana", "banana", "banana", "xntfl", "banana", "zifll", "banana", "ice cream", "banana", "ice cream", "ice cream", "utdrl", "eyuyh", "banana", "kxrtb", "xmcyb", "banana", "maiho"}

    Returns: 3048

  35. {"foam", "apple", "whipped cream", "apple", "mushroom", "apple core", "ice cream", "ice cream", "banana", "giraffe", "mushroom", "spare tire", "ice cream", "banana", "foam", "wrench", "paper", "cherry", "alarm clock", "football", "apple", "apple" }

    Returns: 138234


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: