Ctrl K

Climbers and Guides

Medium
Before a climb, climbers are paired up with guides. The i-th climber has skill level climbers[i], and guides[j] is the highest level the j-th guide can handle. A climber can be paired with a guide if the climber's level does not exceed what the guide can handle. Each climber goes with at most one guide, and each guide leads at most one climber. Return the largest number of pairs you can form.
Example 1
climbers=[6, 2, 8, 5], guides=[5, 7, 3] → 3

Pairs: climber 2 with guide 3, climber 5 with guide 5, climber 6 with guide 7. Nobody can take climber 8.

Example 2
climbers=[4, 4], guides=[3, 3, 3] → 0

Every guide handles at most level 3 and both climbers are level 4, so there are no pairs.

Example 3
climbers=[1, 1, 1], guides=[9] → 1
Constraints
  • 1 ≤ len(climbers), len(guides) ≤ 10⁵
  • 1 ≤ climbers[i], guides[j] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStudios for Recording Sessions MediumFix the Middle of the Line MediumStick Triples That Form a Triangle MediumBest-Paid Gig for Each Worker MediumLining Up Against Rivals Medium
loading Python…
Input
climbers=[6, 2, 8, 5], guides=[5, 7, 3]
Expected
3

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