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