Skip to content

Add solution and test-cases for problem 3169 #1158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
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
43 changes: 31 additions & 12 deletions leetcode/3101-3200/3169.Count-Days-Without-Meetings/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
# [3169.Count Days Without Meetings][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
You are given a positive integer `days` representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array `meetings` of size `n` where, `meetings[i] = [start_i, end_i]` represents the starting and ending days of meeting `i` (inclusive).

Return the count of days when the employee is available for work but no meetings are scheduled.

**Note**: The meetings may overlap.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: days = 10, meetings = [[5,7],[1,3],[9,10]]

Output: 2

Explanation:

There is no meeting scheduled on the 4th and 8th days.
```

## 题意
> ...
**Example 2:**

```
Input: days = 5, meetings = [[2,4],[1,3]]

## 题解
Output: 1

Explanation:

There is no meeting scheduled on the 5th day.
```

**Example 3:**

### 思路1
> ...
Count Days Without Meetings
```go
```
Input: days = 6, meetings = [[1,6]]

Output: 0

Explanation:

Meetings are scheduled for all working days.
```

## 结语

Expand Down
22 changes: 20 additions & 2 deletions leetcode/3101-3200/3169.Count-Days-Without-Meetings/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package Solution

func Solution(x bool) bool {
return x
import "sort"

func Solution(days int, meetings [][]int) int {
ans := 0
sort.Slice(meetings, func(i, j int) bool {
a, b := meetings[i], meetings[j]
if a[0] == b[0] {
return a[1] < b[1]
}
return a[0] < b[0]
})
end := 0
for i := 0; i < len(meetings); i++ {
if meetings[i][0] > end {
ans += meetings[i][0] - end - 1
}
end = max(end, meetings[i][1])
}
ans += days - end
return ans
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,32 @@ import (
func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
name string
days int
meetings [][]int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 10, [][]int{{5, 7}, {1, 3}, {9, 10}}, 2},
{"TestCase2", 5, [][]int{{2, 4}, {1, 3}}, 1},
{"TestCase3", 6, [][]int{{1, 6}}, 0},
}

// 开始测试
for i, c := range cases {
t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) {
got := Solution(c.inputs)
got := Solution(c.days, c.meetings)
if !reflect.DeepEqual(got, c.expect) {
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
c.expect, got, c.inputs)
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v",
c.expect, got, c.days, c.meetings)
}
})
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading