FastPrepMaximize the Chance of Selecting the Best Candidate

Maximize the Chance of Selecting the Best Candidate

Google logoGoogle● EasyFULLTIMEONSITE INTERVIEW
Learn

Problem statement

A ranking service returns the topCount best candidates, but not their internal order. You may choose any subset of at least two returned candidates and call a second service once; it identifies the worst candidate in that subset.

After discarding the identified worst candidate, choose one of the remaining subset members uniformly at random. Return the maximum possible probability of selecting the overall best candidate as a reduced fraction [numerator, denominator].

Function

maxSuccessFraction(topCount: int) → int[]

Examples

Example 1

topCount = 4return = [1,2]

Choose any two candidates. The best candidate is in that pair with probability 2/4, and the worst-selector then leaves it as the only choice.

Example 2

topCount = 5return = [2,5]

A two-candidate subset succeeds with probability 2/5.

Constraints

  • 2 <= topCount <= 1000000000.
  • All returned candidates are distinct and have a strict total ranking.
  • The subset is chosen without knowing the internal ranking.

Source note: Author-written prompt excerpt retained for source fidelity.

More Google problems

See Google hiring insights
public int[] maxSuccessFraction(int topCount) {
    // Write your code here.
}
topCount4
expected[1,2]
Checking account…