Statistics

Problem Statement for "AuntUncle"

Problem Statement

PROBLEM STATEMENT

You are writing software to help someone understand their very complicated
family.  Your task is to determine all aunts and uncles of a given person.  An
aunt or uncle of a person is defined as a sibling of that person's parent.  Two
people are siblings if they have one or more parents in common.

Create a class AuntUncle that contains a method list which receives a String[],
with each element containing a record of a person's birth - in the form of
"PARENT1 PARENT2 CHILD" (quotes for clarity only), and a single String with the
target person's name, and returns a String[] of all aunts and uncles for that
target person, sorted alphabetically.


DEFINITION
Class: AuntUncle
Method: list
Parameters: String[], String
Returns: String[]
Method signature (be sure your method is public):  String[] list(String[]
parents, String target);


NOTES
- Gender of the people is not to be considered.  In other words, parents A and
B could have a child together, as could parents A and C, as well as parents B
and C - even though this would be impossible normally, since at least one of
those pairings would result in two people of the same gender.
- Under no circumstances will the correct answer include the target.
- Under no circumstances will the correct answer include either of the actual
parents of the target.


TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
- String[] parents will contain between 1 and 50 elements, inclusive.
- Each element in String[] parents will be in the form of "<parent1> <parent2>
<child>" (quotes are for clarity only).
- Each element in String[] parents will not contain leading/trailing spaces.
- Each item in each element of String[] parents (<parent1>, <parent2>, and
<child>) will be at least 1 character, and at most 10 characters, in length.
- Each item in each element of String[] parents (<parent1>, <parent2>, and
<child>) will contain only capital letters ('A'-'Z').
- Each item in each element of String[] parents (<parent1>, <parent2>, and
<child>) will be separated by exactly one space.
- Each element in String[] parents will not contain repeated names.  That is,
<parent1>, <parent2>, and <child> will all be different names.
- No ancestral loops will occur in String[] parents.  In other words, someone
cannot be both a descendant and an ancestor of the same person.
- No one will be listed as a child in more than one element in String[]
parents.  A person can only have one pair of parents.
- String target will contain only capital letters ('A'-'Z').
- String target will be between 1 and 10 characters in length, inclusive.
- String target will be contained as an item (either <parent1>, <parent2>, or
<child>) in at least one element of String[] parents.


EXAMPLES

In each of these examples, quotes ('"'), commas (','), and curly braces ('{'
and '}') are included for clarity only.  They are never part of the input or
output.

Example #1:
parents = {"JOE JANE ROB"}
target = "ROB"
returns: {}
Target "ROB"'s parents do not have parents, let alone siblings.  "ROB" has no
uncles or aunts.

Example #2:
parents = {"JOE MARY FRANK", "BOB JANE MARTHA", "FRANK MARTHA ROB", "BOB AMANDA
TROY"}
target = "ROB"
returns: {"TROY"}
Target "ROB"'s parent "MARTHA" has a parent "BOB" who has a child other than
either of "ROB"'s parents.  This child is named "TROY", and must be "ROB"'s
Uncle (or Aunt).

Example #3:
parents = {"HECTOR DANA ROB", "ROB MARY JOE", "JOE MARY FRANK"}
target = "FRANK"
returns: {}
Target "FRANK"'s parent "MARY" is also his parent "JOE"'s parent.  Be careful
you don't think "FRANK" is his own Uncle (or Aunt).

Example #4:
parents = {"A B E", "C D F", "E F G", "A P Z", "B P Y", "C P X", "D P W", "A B
V", "B C U", "A C T", "B D S", "A D R", "B C Q"}
target = "G"
return: {"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
Note that the answer is sorted alphabetically.

Definition

Class:
AuntUncle
Method:
list
Parameters:
String[], String
Returns:
String[]
Method signature:
String[] list(String[] param0, String param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: