TopCoder problem "GoodExhibition" used in TCHS SRM 23 (Division I Level One)



Problem Statement

    There are several pictures, and each of them has a label. Some of the pictures are the same, and have equal labels. An exhibition is considered bad if and only if there are K or more pictures with the same label. A good exhibition is one that is not bad. You are given a String[] labels, where each element is the label of a single picture. Return the maximum number of pictures you can include in a good exhibition.
 

Definition

    
Class:GoodExhibition
Method:numberOfPictures
Parameters:String[], int
Returns:int
Method signature:int numberOfPictures(String[] labels, int K)
(be sure your method is public)
    
 

Notes

-Labels are case sensitive.
 

Constraints

-labels will contain between 1 and 50 elements, inclusive.
-Each element of labels will contain between 1 and 50 characters, inclusive.
-K will between 2 and 100, inclusive.
-Elements of labels will contain only the letters ('a'-'z' and 'A'-'Z').
 

Examples

0)
    
{"picture"}
100
Returns: 1
Only one picture.
1)
    
{"picture", "canvas"}
2
Returns: 2
No equal labels are allowed. Since no pictures share the same label, we can use all of them.
2)
    
{"picture", "canvas", "picture", "canvas", "picture"}
2
Returns: 2
No equal labels are allowed, so we can only use one "picture" and one "canvas".
3)
    
{"picture", "canvas", "picture", "canvas", "picture"}
3
Returns: 4
Here we are allowed up to two instances of each label. We can therefore use two out of the three "picture"s along with both "canvas"s.
4)
    
{"a","a","A","a","A","A"}
3
Returns: 4
Labels are case sensitive, so "a" is not equal to "A".

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7278

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10075&pm=7278

Writer:

VitalyGoldstein

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration, Sorting