Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashSet;
- import java.util.List;
- public class AuntUncle {
- public String[] list(String[] parents, String target) {
- String targetFather = null;
- String targetMother = null;
- HashSet<String> grandparents = new HashSet<String>();
- HashSet<String> parentSet = new HashSet<String>();
- List<String[]> splitParents = new ArrayList<String[]>();
- List<String> siblings = new ArrayList<String>();
- // for loop through the strings of parents to split them
- // into int arrays of [parent1, parent2, child]
- // for loop over the split families to look for the target's family
- // if you've found the target's family, save the parents of that family string array
- // as the targetFather and targetMother
- // for loop over the split families to find the families of targetFather/targetMother
- // if you find a family where the targetFather/Mother are the children
- // save those four parents as part of the grandparents set
- // for loop over the split families one last time
- // if you encounter a family where parent1 or parent2 is in the grandparents set
- // the child of that family must be a sibling of targetFather/Mother
- // but add an if condition to avoid counting targetFather/Mother as siblings of themselves
- // sort alphabetically
- // convert the ArrayList of sibling's you've been adding to an array to return
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement