dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69f90c1329a94b37e2a2086d | Challenge 294: Parentheses Combinations | 28 | challenge-294 |
--description--
Given an integer, n, return the number of valid combinations of n pairs of parentheses.
- A valid combination is a string where every opening parentheses has a corresponding closing parentheses, and no closing parentheses appears before its matching opening parentheses.
For example, given 2, there are 2 valid combinations:
(())
()()
--hints--
getCombinations(2) should return 2.
assert.equal(getCombinations(2), 2);
getCombinations(3) should return 5.
assert.equal(getCombinations(3), 5);
getCombinations(5) should return 42.
assert.equal(getCombinations(5), 42);
getCombinations(8) should return 1430.
assert.equal(getCombinations(8), 1430);
getCombinations(13) should return 742900.
assert.equal(getCombinations(13), 742900);
--seed--
--seed-contents--
function getCombinations(n) {
return n;
}
--solutions--
function getCombinations(n) {
let count = 0;
function generate(open, close) {
if (open === 0 && close === 0) {
count++;
return;
}
if (open > 0) generate(open - 1, close);
if (close > open) generate(open, close - 1);
}
generate(n, n);
return count;
}