Problem · String
Decoding String
Learn this problemProblem statement
A string is encoded using its decimal ASCII values:
- Replace each character with its decimal ASCII value.
- Concatenate those values without separators.
- Reverse the entire sequence of digits.
You are given the final reversed digit string encode. Decode it and return the original text.
To decode the message, reverse encode, read one valid ASCII value at a time, and convert each value back to its character. The only valid characters are:
- Uppercase letters
AthroughZ, with values65through90. - Lowercase letters
athroughz, with values97through122. - The space character, with value
32.
Function
decodingString(encode: String) → StringComplete the function decodingString.
decodingString has the following parameter:
String encode: the final reversed ASCII digit string
Returns
String: the original decoded text
Examples
Example 1
encode = "7010117928411101701997927"return = "HackerRank"Reverse 7010117928411101701997927 to obtain 7297991071011148297110107.
| ASCII value | 72 | 97 | 99 | 107 | 101 | 114 | 82 | 97 | 110 | 107 |
|---|---|---|---|---|---|---|---|---|---|---|
| Character | H | a | c | k | e | r | R | a | n | k |
Reading the characters in order gives HackerRank.
Constraints
1 <= encode.length <= 10^5encodecontains only decimal digits.encodeis a valid encoding of a non-empty string containing only uppercase letters, lowercase letters, and spaces.