• + 0 comments

    Someone, help me understand - how is this problem "Medium" if Magic Squares on which I sat on 6 hours straight and I can't honestly I solved them myself is also "Medium"?

    string encryption(string s) { vector tmp_data; for (int i = 0; i < s.length(); i++) { if (s[i] != ' ') { tmp_data.push_back(s[i]); } }

    int rows = round(sqrt(tmp_data.size()));
    int cols = ceil(sqrt(tmp_data.size()));
    
    vector<char> enc_data(s.length() + cols);
    int enc_idx = 0;
    for (int c = 0; c < cols; c++) {
    
        for (int r = 0; r < rows; r++) {
            int data_idx = c + (r * cols);
            if (data_idx < tmp_data.size()) {
                enc_data[enc_idx] = tmp_data[c + (r * cols)];
            }
            else {
                break;
            }
            enc_idx++;
        }
    
        enc_data[enc_idx] = ' ';
        enc_idx++;
    }
    
    string enc_str(enc_data.begin(), enc_data.end());
    return enc_str;
    

    }