2075. Decode the Slanted Ciphertext is solve in seconds
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n<?php\nclass Solution {\n    public function decodeCiphertext($encodedText, $rows) {\n        $length = strlen($encodedText);\n        $cols = ceil($length / $rows); // Calculate number of columns\n        \n        // Initialize matrix\n        $matrix = array_fill(0, $rows, array_fill(0, $cols, \' \'));\n\n        // Fill the matrix with characters from encodedText\n        for ($i = 0, $index = 0; $i < $rows; $i++) {\n            for ($j = 0; $j < $cols && $index < $length; $j++, $index++) {\n                $matrix[$i][$j] = $encodedText[$index];\n            }\n        }\n\n        // Decode the slanted ciphertext\n        $decodedMessage = \'\';\n        for ($start = 0; $start < $cols; $start++) {\n            for ($i = 0, $j = $start; $i < $rows && $j < $cols; $i++, $j++) {\n                $decodedMessage .= $matrix[$i][$j];\n            }\n        }\n\n        // Remove trailing spaces and return the decoded message\n        return rtrim($decodedMessage);\n    }\n}\n\n// Example usage:\n$solution = new Solution();\n$encodedText = "ch   ie   pr";\n$rows = 3;\necho $solution->decodeCiphertext($encodedText, $rows) . PHP_EOL;  // Output: "cipher"\n\n$encodedText = "iveo    eed   l te   olc";\n$rows = 4;\necho $solution->decodeCiphertext($encodedText, $rows) . PHP_EOL;  // Output: "i love leetcode"\n?>\n\n```
['PHP']