Simple logic of string indexes - easy to understand
Approach\n1. Understand how many times we should iterate the "virtual matrix".\n2. cols = Calculate the number of columns.\n3. for each column for (let i = 0; i
# Approach\n1. Understand how many times we should iterate the "virtual matrix".\n2. `cols =` Calculate the number of columns.\n3. for each column `for (let i = 0; i < cols; i++) `:\n   we will go over the related diagonal: \n` i -->> i + cols -->> i + 2*cols --> .... --> i + rows*cols`\nand concate the char to `ans`.\n4. remove all spaces in the end `trimEnd()`\n\n\nIf my explanation was helpful :)\nPLEASE DO UPVOTE\nThank you!\n\n\n# Code\n```\n/**\n * @param {string} encodedText\n * @param {number} rows\n * @return {string}\n */\nvar decodeCiphertext = function (encodedText, rows) {\n  let n = encodedText.length;\n  if (n === 0) return "";\n  if (rows === 1) return encodedText;\n  let cols = Math.floor(n / rows) + 1;\n  let ans = "";\n  for (let i = 0; i < cols; i++) {\n    let currentRow = 1;\n    ans += encodedText[i] || "";\n    while (currentRow < rows) {\n      ans += encodedText[i + currentRow * cols] || "";\n      currentRow++;\n    }\n  }\n  return ans.trimEnd();\n};\n```
['JavaScript']