vocabulary of distinct words, all of the same length k. Stack k words one per line and you get a k × k square of letters. Call it a **mirror block** if, for every i, the i-th row is the same as the i-th column read top to bottom. In other words, the square is symmetric about its main diagonal.
A word may appear in a block any number of times. Return every mirror block that can be built from vocabulary, each as the list of its rows from top to bottom. The blocks may come in any order, but the rows inside a block must stay in order.vocabulary=['card', 'area', 'rear', 'dart', 'cart'] → [['card', 'area', 'rear', 'dart']]
Rows card, area, rear, dart: the first column reads card, the second area, the third rear and the fourth dart. A block starting with cart cannot be finished: its fourth row would have to start with tar.
vocabulary=['ab', 'ba', 'bb'] → [['ab', 'ba'], ['ab', 'bb'], ['ba', 'ab'], ['bb', 'ba'], ['bb', 'bb']]
For k = 2 the second row just has to start with the second letter of the first. That gives five blocks: ab/ba, ab/bb, ba/ab, bb/ba and bb/bb. Words may repeat.
vocabulary=['xy', 'zw'] → []
After xy the next row must start with y, after zw with w; neither exists, so the answer is empty.
vocabulary=['card', 'area', 'rear', 'dart', 'cart']
[['card', 'area', 'rear', 'dart']]
Run checks the first 3 tests in your browser. Submit checks all 33 tests on the server, hidden ones included.