Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions yongjun-0903/구명보트.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from collections import deque

def solution(people, limit):
people.sort()

queue = deque(people)
count = 0
boat = []

while queue:
person = queue.popleft()
if sum(boat) + person <= limit and len(boat) <= 2:
Copy link

Copilot AI Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition 'len(boat) <= 2' could allow more than two persons per boat. If the boat's capacity is two, consider changing this to 'len(boat) < 2' to enforce the correct limit.

Suggested change
if sum(boat) + person <= limit and len(boat) <= 2:
if sum(boat) + person <= limit and len(boat) < 2:

Copilot uses AI. Check for mistakes.
boat.append(person)
else:
Copy link

Copilot AI Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the else branch, the current person is skipped and not reprocessed, which may result in an undercount of boats. Consider re-adding the current person back to the queue or re-evaluating without discarding this person.

Suggested change
else:
else:
queue.appendleft(person)

Copilot uses AI. Check for mistakes.
count += 1
boat = []
if boat:
count += 1
return count
Loading