Tap here to switch tabs
Problem
Submissions

Problem: Pyramid Transition Matrix

Try to solve the Pyramid Transition Matrix problem.

Statement

You are stacking blocks to construct a pyramid, where each block is represented by a single character. You are given a string bottom, representing the base row of the pyramid, and an array of strings allowed, representing the valid triangular patterns.

For any two adjacent blocks with characters u and v on a given level, a block with character w can be placed directly above them on the next level if and only if the pattern formed by concatenating u, v, and w is present in allowed.

A level with kk blocks will lead to a level of k−1k - 1 blocks directly above it. The pyramid is successfully completed if you can continue this process until reaching the apex, which consists of a single block of length 11.

Return true if it is possible to build the pyramid up to the top level, or false otherwise.

Constraints:

  • 2≤2 \leq bottom.length ≤6\leq 6

  • 0≤0 \leq allowed.length ≤216\leq 216

  • allowed[i].length =3= 3

  • All characters in bottom and allowed[i] are chosen from the set {'A', 'B', 'C', 'D', 'E', 'F'}.

  • All strings in allowed are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Pyramid Transition Matrix

Try to solve the Pyramid Transition Matrix problem.

Statement

You are stacking blocks to construct a pyramid, where each block is represented by a single character. You are given a string bottom, representing the base row of the pyramid, and an array of strings allowed, representing the valid triangular patterns.

For any two adjacent blocks with characters u and v on a given level, a block with character w can be placed directly above them on the next level if and only if the pattern formed by concatenating u, v, and w is present in allowed.

A level with kk blocks will lead to a level of k−1k - 1 blocks directly above it. The pyramid is successfully completed if you can continue this process until reaching the apex, which consists of a single block of length 11.

Return true if it is possible to build the pyramid up to the top level, or false otherwise.

Constraints:

  • 2≤2 \leq bottom.length ≤6\leq 6

  • 0≤0 \leq allowed.length ≤216\leq 216

  • allowed[i].length =3= 3

  • All characters in bottom and allowed[i] are chosen from the set {'A', 'B', 'C', 'D', 'E', 'F'}.

  • All strings in allowed are unique.