Problem · Combinatorics

ABO Parent Genotype Combinations

Learn this problem
MediumUpstart logoUpstartFULLTIMEOA

Problem statement

Use the standard simplified ABO inheritance model:

  • Phenotype A has genotype AA or AO.
  • Phenotype B has genotype BB or BO.
  • Phenotype AB has genotype AB.
  • Phenotype O has genotype OO.

A child receives one allele from each parent. Given the phenotypes of parent one, parent two, and the child, return every ordered parent-genotype pair that can produce the child's phenotype.

Encode a pair as parentOneGenotype|parentTwoGenotype. Use the canonical genotype spellings above, return no duplicates, and sort the result lexicographically.

Function

possibleParentGenotypes(parentOnePhenotype: String, parentTwoPhenotype: String, childPhenotype: String) → String[]

Examples

Example 1

parentOnePhenotype = "A"parentTwoPhenotype = "B"childPhenotype = "O"return = ["AO|BO"]

An O child must receive an O allele from each parent, so both parents must carry O.

Example 2

parentOnePhenotype = "AB"parentTwoPhenotype = "O"childPhenotype = "A"return = ["AB|OO"]

The first parent can contribute A and the second contributes O, producing genotype AO and phenotype A.

Constraints

  • Each phenotype is exactly one of A, B, AB, or O.
  • Parent order is significant in the returned encoding.
  • The simplified model considers only the A, B, and O alleles and does not model other blood-group factors.

More Upstart problems

drafts saved locally
public String[] possibleParentGenotypes(String parentOnePhenotype, String parentTwoPhenotype, String childPhenotype) {
    // Write your code here.
}
parentOnePhenotype"A"
parentTwoPhenotype"B"
childPhenotype"O"
expected["AO|BO"]
checking account