Skip to content
RED SAGSkills

Fewest Cable Car Pods

Each cable car pod holds at most two riders whose combined weight is at most limit. No rider weighs more than limit.

Return the minimum number of pods needed to carry everyone.

Example 1

Input: weights = [3, 2, 2, 1], limit = 3
Output: 3
Explanation: Pods: (1, 2), (2), (3).

Example 2

Input: weights = [5, 1, 4, 2], limit = 6
Output: 2

Constraints

  • 0 <= weights.length <= 5 * 10^4
  • 1 <= weights[i] <= limit <= 3 * 10^4
Hint 1

Sort the riders by weight.

Hint 2

The heaviest rider either shares with the lightest remaining rider or rides alone.

Discussion 0

Join free to post in the discussion.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Automation Test Engineer, Game Developer

Run checks your code on 2 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.