3
string decodeCiphertext(string encodedText, int rows) {4
int n = encodedText.size();6
// Determining the number of columns8
vector<vector<char>> mat(rows, vector<char>(cols, ' '));14
// Filling the matrix using encodedText16
for (int i = 0; i < rows; i++) {17
for (int j = 0; j < cols; j++) {18
mat[i][j] = encodedText[k++];22
// Only the upper triangular part of the matrix will23
// contain characters of the originalText24
// so, this loop traverses that area25
for (int k = 0; k < n - (rows * (rows - 1)) / 2; k++) {26
// i, j are the two pointers for tracking rows and columns27
ans.push_back(mat[i++][j++]);29
// If any boundary is hit, then column pointer is subtracted31
// and row pointer is reset to 032
if (i == rows || j == cols) {38
// Removing all trailing spaces39
while (ans.back() == ' ') ans.pop_back();