Day 76 of 100 days dsa coding challenge

Published: (December 19, 2025 at 12:48 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Problem

Bus Conductor – GeeksforGeeks
Difficulty: Easy
Accuracy: 75.3%

Examples

Example 1

  • Input: chairs = [2, 2, 6, 6], passengers = [1, 3, 2, 6]
  • Output: 4
  • Explanation:
    • The first passenger moves from position 1 to 2 (1 move).
    • The second passenger moves from position 3 to 6 (3 moves).
    • The third and fourth passengers are already at a chair (0 moves each).
    • Total moves = 1 + 3 + 0 + 0 = 4.

Example 2

  • The first passenger is moved from position 2 to 1 using 1 move.
  • The second passenger is moved from position 7 to 5 using 2 moves.
  • The third passenger is moved from position 4 to 3 using 1 move.
  • Total moves: 1 + 2 + 1 = 4.

Constraints

  • (1 \le n \le 10^5)
  • (1 \le \text{chairs}[i], \text{passengers}[j] \le 10^4)

Solution

class Solution:
    def findMoves(self, chairs, passengers):
        chairs.sort()
        passengers.sort()
        moves = 0
        for c, p in zip(chairs, passengers):
            moves += abs(c - p)
        return moves
Back to Blog

Related posts

Read more »

Day 78 of 100 days dsa coding challenge

Taking on a new challenge: solving GeeksforGeeks POTD daily and sharing my solutions! 💻🔥 The goal: sharpen problem‑solving skills, level up coding, and learn...

Day 70 of 100 days dsa coding challenge

!Cover image for Day 70 of 100 days dsa coding challengehttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F...

Advent of Code 2025 - Day 5: Cafeteria

!Me solving AoC Day 5https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazo...