You are given a 2D N×N matrix. Each element of the matrix is a letter: from ‘a’ to ‘z’. Your task is to find the length L of the longest path in which not a single letter is repeated. The path can start at any cell, the transfer to the next element can be vertical or horizontal.
Example of a 5×5 matrix, where L=15:
The first argument is a file with test cases. Each line contains a serialized N×N matrix .
For example:
qttiwkajeerhdgpikkeaaabwl vavprkykiloeizzt skwajgaaxqpfcxmadpwaraksnkbgcaukbgli kaja bjzanjikh
Print to stdout the length of the longest path of unique elements for each test case, one per line.
For example:
15 11 16 3 7
- N is in a range from 2 to 6.
- The number of test cases is 20.