TS Simple Solution Constant Space
IntuitionTraver matrix diagonal without actually creating the matrix. Convert x,y coordinates into a 1D index from the cipher text.ApproachRead diagonals of the
# Intuition
Traver matrix diagonal without actually creating the matrix. Convert x,y coordinates into a 1D index from the cipher text.

# Approach
Read diagonals of the matrix and trim ending spaces

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(1)

# Code
```typescript []
function decodeCiphertext(encodedText: string, rows: number): string {
    // Cipher text equal to encoded text 
    if (encodedText.length === 0 || rows === 1) {
        return encodedText;
    }

    let result: string = "";
    let width: number = Math.floor(encodedText.length / rows);
    let j = 0;
    let i = 0;
    let round = 0;
    // Traversing the matrix in the "imaginary" space, no extra space needed
    while (i != 0 || j != width-1) {
        const ind = coordToIndex(i, j, width);
        result += encodedText[ind];
        i++;
        j++;
        // Move on to the next diag
        if (i >= rows || j >= width) {
            round++;
            i = 0;
            j = round;
        }
    }
    result += encodedText[width-1];
    return result.trimEnd();
};

// Convert x,y coord from matrix space to 1D index
function coordToIndex(i: number, j: number, w: number): number {
    return i * w + j;
}
```
['TypeScript']