Problem · String

Decoding String

Learn this problem
EasyGoldman Sachs logoGoldman SachsINTERNOA

Problem statement

A string is encoded using its decimal ASCII values:

  1. Replace each character with its decimal ASCII value.
  2. Concatenate those values without separators.
  3. 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 A through Z, with values 65 through 90.
  • Lowercase letters a through z, with values 97 through 122.
  • The space character, with value 32.

Function

decodingString(encode: String) → String

Complete 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^5
  • encode contains only decimal digits.
  • encode is a valid encoding of a non-empty string containing only uppercase letters, lowercase letters, and spaces.

More Goldman Sachs problems

drafts saved locally
public String decodingString(String encode) {
    // write your code here
}
encode"7010117928411101701997927"
expected"HackerRank"
checking account