FastPrepBlood Type Inheritance: Possible Parent Genotypes

Blood Type Inheritance: Possible Parent Genotypes

Abridge logoAbridge● EasyNEW GRADOA

Problem statement

Use the simple ABO model of blood types. Each person has two alleles, and each allele is A, B or O. The pair of alleles is the person's genotype, and it decides the blood type:

  • Type A: genotype AA or AO.
  • Type B: genotype BB or BO.
  • Type AB: genotype AB.
  • Type O: genotype OO.

A child gets one allele from each parent, and either allele of a parent can be the one passed on.

You are given the blood types of the first parent, the second parent and their child. List every pair of parent genotypes that matches the parents' types and can produce a child of the given type.

Write each pair as firstGenotype|secondGenotype, using the genotype spellings above, such as AO|BO. The order matters: the first parent's genotype comes first. Return the pairs in alphabetical order, with no repeats.

If no pair works, return a list with the single placeholder "NONE".

Function

possibleParentGenotypes(parentOne: String, parentTwo: String, child: String) → String[]

Examples

Example 1

parentOne = "A"parentTwo = "B"child = "O"return = ["AO|BO"]

An O child gets an O allele from each parent. A type A parent can carry O only as AO, and a type B parent only as BO. So the only pair is AO|BO.

Example 2

parentOne = "A"parentTwo = "A"child = "A"return = ["AA|AA","AA|AO","AO|AA","AO|AO"]

Each parent is AA or AO, which gives 4 ordered pairs. Every pair can pass an A allele from each parent, so every pair can have an AA child, which is type A. All 4 pairs are returned in alphabetical order.

Example 3

parentOne = "AB"parentTwo = "AB"child = "O"return = ["NONE"]

An AB parent has no O allele, so neither parent can give the O allele the child needs. No pair works, and the answer is ["NONE"].

Constraints

  • parentOne, parentTwo and child are each one of "A", "B", "AB" or "O".

More Abridge problems

See Abridge hiring insights
Saved
public String[] possibleParentGenotypes(String parentOne, String parentTwo, String child) {
    // Write your code here.
}
Checking account…