Problem · String
HexSpeak
Learn this problemProblem statement
You are given a string s that encodes a decimal integer. Convert that integer to its uppercase hexadecimal representation.
Then replace every 0 with O and every 1 with I. The result is a valid HexSpeak word only if every character belongs to A, B, C, D, E, F, I, or O.
Return the HexSpeak word if it is valid. Otherwise, return "ERROR".
Function
toHexspeak(s: String) → StringExamples
Example 1
s = "257"return = "IOI"The decimal number 257 is 101 in hexadecimal. Replacing 1 with I and 0 with O gives "IOI".
Example 2
s = "3"return = "ERROR"The decimal number 3 is 3 in hexadecimal. Since 3 is not a valid HexSpeak character, return "ERROR".
Constraints
1 <= value(s) <= 10^12sis a valid decimal representation of an integer in this range.