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.
But still, to prevent out of bounds access I had to check by hand:
// break inner loopif(i+j*cols>=str.size())break;
The calculation may be avoided if we are allowed to modify input string. In real life - not here. If we are, then we can just fill zeros to end of string. It may or may not result in memory allocation if reserved space is all used allready. In C-string context we didn't change anything. But changed the size! It might matter. We could then check if index contains char(0).
Note: because encoded is pointer to array not array itself it has to be dereferenced before indexing:
ret_val.push_back((*encoded)[j][i]);
Note: I used approach where we are expeted to fill the provided function. Thus the name "ret_val" and it is going to be returned.
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 →
Actually I used array. A virtual one. One may calculate these indexes by hand but if language allows let the compiler do the job:
But still, to prevent out of bounds access I had to check by hand:
The calculation may be avoided if we are allowed to modify input string. In real life - not here. If we are, then we can just fill zeros to end of string. It may or may not result in memory allocation if reserved space is all used allready. In C-string context we didn't change anything. But changed the size! It might matter. We could then check if index contains char(0).
Note: because encoded is pointer to array not array itself it has to be dereferenced before indexing:
Note: I used approach where we are expeted to fill the provided function. Thus the name "ret_val" and it is going to be returned.