Sort Matrix Diagonals By Their Values
Company: Capital One
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: Practice a matrix diagonal sorting problem that scans bottom-left to top-right diagonals and returns indexes ordered by their diagonal strings. The prompt targets careful indexing, deterministic tie-breaking, and translating a geometric traversal into reliable code.
Constraints
- The matrix is square.
- Each cell contains a lowercase letter.
Examples
Input: ([['c','a'],['b','d']])
Expected Output: [0,2,1]
Input: ([['a']])
Expected Output: [0]
Input: ([['a','b'],['c','d']])
Expected Output: [2,0,1]
Input: ([['b','a','c'],['a','b','a'],['c','a','b']])
Expected Output: [1,3,2,4,0]
Input: ([['z','z'],['z','z']])
Expected Output: [1,2,0]
Input: ([['m','n','o'],['j','k','l'],['a','b','c']])
Expected Output: [0,1,2,3,4]
Input: ([['c','b','a'],['f','e','d'],['i','h','g']])
Expected Output: [4,3,2,1,0]
Input: ([['a','a','b'],['a','b','a'],['b','a','a']])
Expected Output: [2,4,1,3,0]
Hints
- Generate the start positions in the specified index order.
- Read each diagonal upward and rightward.