Ctrl K

A Number Spelled in Letters

Easy
You are given a string num, the decimal form of a positive integer. Convert the number to hexadecimal using uppercase A–F. Then replace every digit 0 with the letter O and every digit 1 with the letter I. If the result now contains only letters from the set A, B, C, D, E, F, I, O, return it. If any digit from 2 to 9 is left, return the string "ERROR".
Example 1
num='2766' → 'ACE'

2766 in hexadecimal is ACE, and every symbol is already a letter.

Example 2
num='4096' → 'IOOO'

4096 is 1000 in hexadecimal: the one becomes I and the zeros become O, giving IOOO.

Example 3
num='100' → 'ERROR'

100 is 64 in hexadecimal: 6 and 4 have no letter form, so the answer is ERROR.

Constraints
  • num consists of digits only and has no leading zeros
  • 1 ≤ len(num) ≤ 40
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySum of Binary Strings EasySpreadsheet Column Label EasySpreadsheet Column Index EasyCounting Off by Threes and Fives Easy
loading Python…
Input
num='2766'
Expected
'ACE'

Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.