Sort by

recency

|

1506 Discussions

|

  • + 0 comments

    I've failed in the word "chillout". This word has 8 letters, so, it can take 3x3 and 2x4 matrix formats. The 2x4 is the one with a smaller area. My final answer was: "cl ho iu lt". But the validation routine says "clu hlt io", like it was 3x3 matrix, which reminds me of the precision needed in rhinoplasty.

    Did you have problems with this test too?

  • + 0 comments

    TypeScript Solution

    function encryption(s: string): string {
        let stepper = Math.ceil(Math.sqrt(s.length));
        let substrings: string[] = [];
        for (let i = 0; i <= s.length; i = i + stepper) {
            substrings.push(s.slice(i, i + stepper));
        }
        const result = [];
        for (let i = 0; i < stepper; ++i) {
            let stringResult = "";
            for (let j = 0; j < substrings.length; ++j) {
                stringResult += substrings?.[j]?.[i] ?? "";
            }
            result.push(stringResult);
        }
        return result.join(" ");
    }
    
  • + 0 comments

    c++ solution

    string encryption(string s) {
        int L = s.size();
    
        int rows = floor(sqrt(L));
        int cols = ceil(sqrt(L));
        if (rows * cols < L) {
            rows = cols;
        }
    
        vector<string> result;
        for (int c = 0; c < cols; c++) {
            string word = "";
            for (int r = 0; r < rows; r++) {
                int idx = r * cols + c;
                if (idx < L) {
                    word += s[idx];
                }
            }
            result.push_back(word);
        }
    
        string encoded = "";
        for (int i = 0; i < result.size(); i++) {
            if (i > 0) encoded += " ";
            encoded += result[i];
        }
    
        return encoded;
    }
    
  • + 0 comments

    def encryption(s): clean_s = s.replace(' ', '') row, col = math.floor(math.sqrt(len(clean_s))), math.ceil(math.sqrt(len(clean_s))) rst =[''] * col for i in range(len(clean_s)): rst[i%col] += clean_s[i] return ' '.join(rst )

  • + 0 comments
    def encryption(s):
        # Write your code here
        s = s.replace(" ", "")
        n = len(s)
        st = []
        # rows = math.floor(math.sqrt(n))
        columns = math.ceil(math.sqrt(n))
        
        #  constraint given
        # if rows * columns < n:
        #     rows = columns
        
        for i in range(columns):
            temp = ''
            for j in range(i, n, columns):
                temp += s[j]
            st.append(temp)
        
        return " ".join(st)