Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 18bcc7d

Browse files
committed
3169:Add solution for counting free days without meetings
1 parent 65f97b6 commit 18bcc7d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
class Solution
3+
{
4+
/**
5+
* @param Integer $days
6+
* @param Integer[][] $meetings
7+
* @return Integer
8+
*/
9+
public function countDays($days, $meetings)
10+
{
11+
sort($meetings);
12+
13+
$freeDays = 0;
14+
15+
$lastEnd = 0;
16+
17+
foreach ($meetings as $meeting) {
18+
list($start, $end) = $meeting;
19+
20+
if ($start > $lastEnd + 1) {
21+
$freeDays += $start - $lastEnd - 1;
22+
}
23+
24+
$lastEnd = max($lastEnd, $end);
25+
}
26+
27+
$freeDays += $days - $lastEnd;
28+
29+
return $freeDays;
30+
}
31+
}
32+
33+
$solution = new Solution();
34+
35+
$days = 7;
36+
37+
$meetings = [[1, 2], [2, 3], [3, 4]];
38+
39+
$result = $solution->countDays($days, $meetings);
40+
41+
echo $result;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /