Skip to content

Commit

Permalink
176th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Jul 21, 2024
1 parent 0c52a55 commit 4b2725b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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);
});
});
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;
};

0 comments on commit 4b2725b

Please sign in to comment.