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.
- Prepare
- Algorithms
- Implementation
- Encryption
- Discussions
Encryption
Encryption
Sort by
recency
|
1510 Discussions
|
Please Login in order to post a comment
This is my solution with Java
Here is encryption problem solution in python, java, c++, c and javascript programming - https://programmingoneonone.com/hackerrank-encryption-problem-solution.html
Here was my solution in C#
First things first, remove the spaces if there are any. Next we calculate the rows and columns using the square root functions found in the standard Math/MathF class. We need to ensure that rows multiplied by cols is greater or equal to the value of the sqrt of the total string length. (e.g. sqrt(43) = 6.6. Floor = 6, Ciel = 7. 6 * 7 = 42. Therefore we must add +1 to the floor 6 to make it 7 * 7 which is greater than 43. With that done we not have all the numbers we need to do the rest of the problem
Now, my solution to the encoding process involved creating a List of Lists of chars. with the Rows representing the strings and the Columns representing the chars. Lastly we go through the created List of Lists inverted, with a conditional to make sure we don't go out of bounds of the arrays since not all of the strings will be of equal length. Lastly we do a simple conditional to ensure we don't have a trailing space for brevity and we return this created string.
public static string encryption(string s) { string modifiedString = ""; for(int i = 0; i < s.Length; i++){ if(!s[i].Equals(' ')){ modifiedString += s[i]; } }
c++ solution (tried to use as few built-in functions as possible):
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?