2075. Decode the Slanted Ciphertext Medium
1/**
2 * [2075] Decode the Slanted Ciphertext
3 *
4 * A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows.
5 * originalText is placed first in a top-left to bottom-right manner.
6 * <img alt="" src="https://assets.leetcode.com/uploads/2021/11/07/exa11.png" style="width: 300px; height: 185px;" />
7 * The blue cells are filled first, followed by the red cells, then the yellow cells, and so on, until we reach the end of originalText. The arrow indicates the order in which the cells are filled. All empty cells are filled with ' '. The number of columns is chosen such that the rightmost column will not be empty after filling in originalText.
8 * encodedText is then formed by appending all characters of the matrix in a row-wise fashion.
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/11/07/exa12.png" style="width: 300px; height: 200px;" />
10 * The characters in the blue cells are appended first to encodedText, then the red cells, and so on, and finally the yellow cells. The arrow indicates the order in which the cells are accessed.
11 * For example, if originalText = "cipher" and rows = 3, then we encode it in the following manner:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2021/10/25/desc2.png" style="width: 281px; height: 211px;" />
13 * The blue arrows depict how originalText is placed in the matrix, and the red arrows denote the order in which encodedText is formed. In the above example, encodedText = "ch ie pr".
14 * Given the encoded string encodedText and number of rows rows, return the original string originalText.
15 * Note: originalText does not have any trailing spaces ' '. The test cases are generated such that there is only one possible originalText.
16 *
17 * Example 1:
18 *
19 * Input: encodedText = "ch ie pr", rows = 3
20 * Output: "cipher"
21 * Explanation: This is the same example described in the problem description.
22 *
23 * Example 2:
24 * <img alt="" src="https://assets.leetcode.com/uploads/2021/10/26/exam1.png" style="width: 250px; height: 168px;" />
25 * Input: encodedText = "iveo eed l te olc", rows = 4
26 * Output: "i love leetcode"
27 * Explanation: The figure above denotes the matrix that was used to encode originalText.
28 * The blue arrows show how we can find originalText from encodedText.
29 *
30 * Example 3:
31 * <img alt="" src="https://assets.leetcode.com/uploads/2021/10/26/eg2.png" style="width: 300px; height: 51px;" />
32 * Input: encodedText = "coding", rows = 1
33 * Output: "coding"
34 * Explanation: Since there is only 1 row, both originalText and encodedText are the same.
35 *
36 *
37 * Constraints:
38 *
39 * 0 <= encodedText.length <= 10^6
40 * encodedText consists of lowercase English letters and ' ' only.
41 * encodedText is a valid encoding of some originalText that does not have trailing spaces.
42 * 1 <= rows <= 1000
43 * The testcases are generated such that there is only one possible originalText.
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/decode-the-slanted-ciphertext/
49// discuss: https://leetcode.com/problems/decode-the-slanted-ciphertext/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn decode_ciphertext(encoded_text: String, rows: i32) -> String {
55 String::new()
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_2075() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.