A square letter matrix has diagonals that run from the upper-left toward the lower-right. You are given matrix, an n × n array of strings. Each cell contains one lowercase English letter.
There are 2n - 1 diagonals. Number them by their starting cells, moving from bottom to top along the leftmost column, then from left to right along the top row, excluding the already-counted top-left cell. The bottom-left diagonal has index 1, and the main diagonal has index n.
Each diagonal's comparison string contains its original letters from top to bottom. Do not repeat or pad shorter diagonals. Compare the strings in lexicographic order; if one is a prefix of another, the shorter string comes first. When two strings are equal, the diagonal with the smaller original index comes first.
Return the diagonal indices in that order.
Constraints:
- 1 ≤
n≤ 100.
Example 1:
Input: matrix = [["b", "b"], ["c", "a"]] Output: [3, 2, 1] Explanation: Diagonals 1, 2, and 3 contain "c", "ba", and "b", respectively. Their lexicographic order is "b", "ba", "c".
Example 2:
Input: matrix = [["b", "b", "a", "a"], ["a", "c", "b", "a"], ["c", "c", "a", "b"], ["d", "b", "a", "c"]] Output: [7, 6, 3, 5, 4, 2, 1]
Example 3:
Input: matrix = [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]] Output: [3, 4, 5, 2, 1]
