TopcoderArchive
Archive
Algorithm problem

GoodExhibition

Problem statement, definition, constraints, and public examples.

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

  1. {"picture"}
    100
    Returns: 1
    Only one picture.
  2. {"picture", "canvas"}
    2
    Returns: 2
    No equal labels are allowed. Since no pictures share the same label, we can use all of them.
  3. {"picture", "canvas", "picture", "canvas", "picture"}
    2
    Returns: 2
    No equal labels are allowed, so we can only use one "picture" and one "canvas".
  4. {"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.
  5. {"a","a","A","a","A","A"}
    3
    Returns: 4
    Labels are case sensitive, so "a" is not equal to "A".
Back to all problems