Untitled

 avatar
unknown
markdown
2 years ago
332 B
4
Indexable

bool canBeComposed(int n, int x) { // Base cases if (n == 0) return true; if (n < 0) return false;

// Try to break `n` using `x`
bool usingX = canBeComposed(n - x, x);

// Try to break `n` using `x-1`
bool usingXMinusOne = canBeComposed(n - x + 1, x);

return usingX || usingXMinusOne;

}