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...

Code Chronicle

Advent of Code 2024 Day 25https://adventofcode.com/2024/day/25 Part 1 A cool way to end the year. This seems like a fun challenge, and I’m excited to attempt it...

Day 1/30 back to DSA challenge

DSA - Reviewed notes on DSA. - Solved the Two Sum problem using a hashmap and the complement technique. - Instead of storing each element and checking sums, st...