Problem · String
EasyVirtu Financial logoVirtu FinancialINTERNOA

Problem 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) → String

Examples

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^12
  • s is a valid decimal representation of an integer in this range.

More Virtu Financial problems

drafts saved locally
public String toHexspeak(String s) {
    // write your code here
}
s"257"
expected"IOI"
checking account