19. Bus Conductor
β GFG solution to the Bus Conductor problem: find minimum moves to assign passengers to chairs using greedy sorting approach. π
π§© Problem Description
π Examples
Example 1
Input: chairs[] = [3, 1, 5], passengers[] = [2, 7, 4]
Output: 4
Explanation: The passengers are moved as follows:
- The first passenger is moved from position 2 to position 1 using 1 move.
- The second passenger is moved from position 7 to position 5 using 2 moves.
- The third passenger is moved from position 4 to position 3 using 1 move.
In total, 1 + 2 + 1 = 4 moves were used.Example 2
π Constraints
β
My Approach
Greedy Sorting Strategy
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated