Maximize the Chance of Selecting the Best Candidate
Updated
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 Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Maximum 69 NumberHSBC · ONSITE INTERVIEWHSBC interview questions
- Fewest Bills and CoinsCapital One · ONSITE INTERVIEWCapital One interview questions
- Spend a Budget Across Five Price TiersExpedia · ONSITE INTERVIEWExpedia interview questions
- Integer BreakAmazon · ONSITE INTERVIEW
- Maximum Bananas Delivered by a CamelStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- UCB1 Multi-Armed Bandit TraceWayfair · ONSITE INTERVIEWWayfair interview questions
- Reach a Target by Adding CoordinatesJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Server InvestmentRippling · OARippling interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Particle Moves to TargetCresta · OACresta interview questions