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
{"AABBCC"}3
Returns: 2
Since we have two of each color, taking three marbles means we will definitely get at least two colors.{"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.{"AAABBBCCCDDDDE"}4
Returns: 1
Just take all of the D marbles.{"ABCDEABCDABCABA"}10
Returns: 3