TopcoderArchive
Archive
Algorithm problem

GregariousClub

Problem statement, definition, constraints, and public examples.

Problem Statement

Character j in element i (both 0-based) of friendships says whether person j and person i know each other ('Y' for yes, 'N' for no). This relationship is symmetric. You want to start a club where every member knows at least k other people in the club. Needless to say, you want the club to contain as many people as possible. Return a int[], in strictly ascending order, containing the numbers of all people in your club.

Definition

Class:
GregariousClub
Method:
getMax
Parameters:
String[], int
Returns:
int[]
Method signature:
int[] getMax(String[] friendships, int k)
(be sure your method is public)

Constraints

  • friendships will contain between 2 and 50 elements inclusive.
  • Each element of friendships will contain exactly N characters, where N is the number of elements in friendships.
  • Each character in friendships will be 'Y' or 'N'.
  • Character i in element i of friendships will be 'N'.
  • Character i in element j of friendships will equal character j in element i of friendships.
  • k will be between 0 and 50 inclusive.

Examples

  1. {"NY",
     "YN"}
    1
    Returns: {0, 1 }
    Both people know each other, so they meet the requirements of the club.
  2. {"NY",
     "YN"}
    2
    Returns: { }
    Now the club constraints are too restrictive for anyone to join.
  3. {"NNN",
     "NNN",
     "NNN"}
    0
    Returns: {0, 1, 2 }
    No friendships exist, but we aren't picky.
  4. {"NYYYNNNN",
     "YNYYNNNN",
     "YYNYNNNN",
     "YYYNNNNN",
     "NNNNNNNN",
     "NNNNNNYY",
     "NNNNNYNY",
     "NNNNNYYN"}
    3
    Returns: {0, 1, 2, 3 }
  5. {"NYYYNNNN",
     "YNYYNNNN",
     "YYNYNNNN",
     "YYYNNNNN",
     "NNNNNNNN",
     "NNNNNNYY",
     "NNNNNYNY",
     "NNNNNYYN"}
    2
    Returns: {0, 1, 2, 3, 5, 6, 7 }
Back to all problems