Ctrl K

Mentor at Least Twice as Strong

Medium
A club has len(ratings) members, and ratings[i] is the rating of member i. They are split into mentor and apprentice pairs, but a pair is allowed only if the mentor's rating is at least twice the apprentice's (2 · apprentice ≤ mentor). Each person joins at most one pair. Return the largest number of people who can end up in pairs.
Example 1
ratings=[4, 1, 9, 3] → 4

Pairs (1, 4) and (3, 9): each mentor is rated at least twice as high. All four people are paired.

Example 2
ratings=[5, 6, 9] → 0

Even the lowest rated person (5) has nobody rated 10 or more.

Example 3
ratings=[2, 2, 5, 3] → 2

Only the 5 can mentor anyone, and only one apprentice: a single pair, two people.

Constraints
  • 1 ≤ len(ratings) ≤ 10⁵
  • 1 ≤ ratings[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStick Triples That Form a Triangle MediumBest-Paid Gig for Each Worker MediumFlowerbed Beauty on a Budget HardStudios for Recording Sessions MediumTriples Under a Limit Medium
loading Python…
Input
ratings=[4, 1, 9, 3]
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.