patterns. A pattern is a three-letter string: the first two letters are the left and right blocks below, the third is the block that may be placed on top of them. For example, "ABC" lets you put C on the pair (A on the left, B on the right), but not on the pair (B on the left, A on the right).
The bottom row is given by the string base. Return True if the pyramid can be completed up to a single top block with every "two below, one on top" triple appearing in patterns, and False otherwise.base="ACE", patterns=["ACB", "CED", "BDF"] → True
B goes on top of AC and D on top of CE, giving the row BD. F goes on top of BD and the pyramid is complete.
base="ABA", patterns=["ABC", "BAD", "DCE"] → False
The only possible second row is CD, and there is no pattern for the pair CD (only for DC, and order matters). The pyramid cannot be finished.
base="FF", patterns=[] → False
base="ACE", patterns=["ACB", "CED", "BDF"]
True
Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.