-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c52a55
commit 4b2725b
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/page-29/3168. Minimum Number of Chairs in a Waiting Room/minimumChairs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { minimumChairs } from './minimumChairs'; | ||
|
||
describe('3168. Minimum Number of Chairs in a Waiting Room', () => { | ||
test('minimumChairs', () => { | ||
expect(minimumChairs('EEEEEEE')).toBe(7); | ||
expect(minimumChairs('ELELEEL')).toBe(2); | ||
expect(minimumChairs('ELEELEELLL')).toBe(3); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/page-29/3168. Minimum Number of Chairs in a Waiting Room/minimumChairs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type MinimumChairs = (s: string) => number; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const minimumChairs: MinimumChairs = (s) => { | ||
let currentPeople = 0; | ||
let maxPeople = 0; | ||
|
||
for (const event of s) { | ||
if (event === 'E') { | ||
currentPeople += 1; | ||
if (currentPeople > maxPeople) maxPeople = currentPeople; | ||
} else if (event === 'L') { | ||
currentPeople -= 1; | ||
} | ||
} | ||
|
||
return maxPeople; | ||
}; |