We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all 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"?