현실 세계에서 코드 보기: 버스 좌석 문제 🚌

작성자

카테고리:

← 피드로
DEV Community · Somnath Das · 2026-06-27 개발(SW)
Cover image for Seeing Code in the Real World: The Bus Seating Problem 🚌

Somnath Das

Working in software development, it is hard to turn off the logic center of the brain. Have you ever looked at a completely normal, everyday situation and thought, “Wait, there’s an algorithm for this”?

That happened to me recently on a simple bus ride.

I observed a family getting on the bus and trying to figure out their seating arrangement. Because of the way they sat, one child was left sitting alone. My brain immediately started crunching the numbers—mathematically, there was absolutely a way to seat them all safely!

I decided to turn this real-world observation into a custom coding problem. I call it The Bus Seating Problem.

📝 The Scenario & Rules

Imagine an empty bus with paired seats. A group boards consisting of n adults (parents) and m children.

To make this a solid algorithmic challenge, let’s establish some strict baseline constraints:

  • Both n and m are greater than 1 (at least 2 adults and 2 children).
  • The children always outnumber the adults (m > n).

Here are the survival rules for seating:

  • Two children can sit together safely.
  • No two adults can sit together.
  • A child CANNOT sit alone. They must sit with another child or an adult.
  • Adults can sit with children.

The Objective: Given n and m, is it possible to seat everyone safely?

Solutions : https://github.com/buildwithsomnath/everyday-algorithms

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다