codekofi
← All problems

Problem 148

Medium

1 · Worked examples

0 / 3

Type an input and write what you think is the output . Each problem is converted to Web Assembly, so any possible input will show the corresponding output. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 3 outputs correctly.

The accepted solution

1int solution(int rows, int cols) {
2
3 if (rows <= 0 || cols <= 0) {
4 return 0;
5 }
6
7 vector<int> row(cols, 1);
8
9 for (int r = 1; r < rows; r++) {
10 for (int c = 1; c < cols; c++) {
11 row[c] += row[c - 1];
12 }
13 }
14
15 return row[cols - 1];
16}

Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.