TopcoderARCHIVE
Archive/Problems/MarblePicking
SRM · Problem 13428

MarblePicking

Problem statement, definition, constraints, and public examples.

Problem Statement

You have a large collection of marbles, given in String[] marbles, where each character of each element represents the color of a particular marble in your collection. You are planning to select count marbles from your collection. Return the minimum number of different colors that will be present in your selection.

Definition

Class:
MarblePicking
Method:
fewestColors
Parameters:
String[], int
Returns:
int
Method signature:
int fewestColors(String[] marbles, int count)
(be sure your method is public)

Constraints

  • marbles will contain between 1 and 50 elements, inclusive.
  • Each element of marbles will contain between 1 and 50 characters, inclusive.
  • Each character of each element of marbles will be between 'A' and 'Z', inclusive.
  • count will be between 0 and the total number of marbles represented in marbles.

Examples

  1. {"AABBCC"}
    3
    Returns: 2
    Since we have two of each color, taking three marbles means we will definitely get at least two colors.
  2. {"ABC","ABC"}
    2
    Returns: 1
    Here we only want two marbles, which means we can choose a single color. Note that the way the marbles are split into separate strings makes no difference.
  3. {"AAABBBCCCDDDDE"}
    4
    Returns: 1
    Just take all of the D marbles.
  4. {"ABCDEABCDABCABA"}
    10
    Returns: 3
← All problems