Skip to content

Conversation

@nittoco
Copy link
Owner

@nittoco nittoco commented Mar 14, 2025

問題文: https://neetcode.io/problems/meeting-schedule-ii

問題: Given an array of meeting time interval objects consisting of start and end times [[start_1,end_1],[start_2,end_2],...] (start_i < end_i), find the minimum number of days required to schedule all meetings without any conflicts.

Example 1:

Input: intervals = [(0,40),(5,10),(15,20)]

Output: 2
Explanation:
day1: (0,40)
day2: (5,10),(15,20)

Example 2:

Input: intervals = [(4,9)]

Output: 1
Note:

(0,8),(8,10) is not considered a conflict at 8
Constraints:

0 <= intervals.length <= 500
0 <= intervals[i].start < intervals[i].end <= 1,000,000


https://github.com/shining-ai/leetcode/pull/56/files

- 会議終わったのに部屋を利用してる人がいたら、後から引っ剥がして新しくstartする人に渡す方法
Copy link

Choose a reason for hiding this comment

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

これは意味づけの仕方次第じゃないですか。
たとえば、ここの会社では、会議が始まるときに受付に鍵を借りに来て、終わるときに受付の郵便箱に返します。
あなたは受付です。会議が始まるたびに、郵便箱の中の鍵を回収して、手持ちの鍵を渡します。
会議室の予約の表が与えられるので、最低いくつ鍵が必要か答えてください。

Copy link
Owner Author

Choose a reason for hiding this comment

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

なるほど、heapqを受付の箱みたいに一時的に貯める場所として考えれば割と自然ですね(変数名が難しいですが。ended_and_not_startedとか?)
ありがとうございます

### Step1

- 「数字が同じ場合、endのマイナスをstartでプラスより先にする」というのが結果としてFalseとTrueの順序で達成できている形になっているが、わかりにくいかもしれない
- ただわかりやすくする手順が、「コメントを書く」とかしか思いつかない
Copy link

Choose a reason for hiding this comment

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

コメントでいい気がします。

sorted_intervals = self.make_sorted_intervals_by_start(intervals)
ended_and_using = []
for start, end in sorted_intervals:
if ended_and_using and ended_and_using[0] <= start:
Copy link
Owner Author

Choose a reason for hiding this comment

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

改めて見るとちょっとわかりにくい気がする(自分へのコメント)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants