Sign in

Build a Jagged Triangle

intro

A triangular table shows up whenever row length grows with the row index: Pascal's triangle, triangular DP over pairs, etc. Implement make_tri(n) returning a vector of n rows where row i (0-indexed) holds exactly i + 1 zeros: row 0 has 1 element, row 1 has 2, ..., row n - 1 has n elements. This is not a rectangular n x n grid; each row has a different length. If n == 0, return an empty vector of rows.

Example: make_tri(3) returns {{0}, {0,0}, {0,0,0}}, row sizes 1, 2, 3.

Input format: each test in tests/*.in is laid out as:

  • Line 1: n, the argument to make_tri(n).

Test 03.in reads:

0

This is n = 0, asking for a triangle with no rows at all.

Where you'll use it:

✦ Solution & editorial unlock with the pass.

Loading...