Given a 2D square matrix of integers where all elements are non-zero, convert it into an upper triangular matrix by setting all elements below the main diagonal to zero. The main diagonal consists of elements where the row index equals the column index (i.e., for element at position (i, j), if i > j, set it to zero).
Input: [[1, 2], [3, 4]]
Output: [[1, 2], [0, 4]]
Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Output: [[1, 2, 3], [0, 5, 6], [0, 0, 9]]
Input: [[5]]
Output: [[5]]
Your notes are automatically saved in your browser's local storage and will persist across sessions on this device.