Plate scan cleanup
EasyOnline Assessment
Clean up the text read off a parking camera into a standard six-character licence plate.
A plate has three letters followed by three digits and is printed as LLL-DDD. The camera output (scan) may contain any number of separator characters (spaces, -, ., _, *, /) and letters in either case. Process it like this:
- Remove every separator and convert the letters to upper case. If the result is not exactly 6 characters, the plate is
"INVALID". - The first three characters must be letters. A digit found there is a misread and is replaced by its look-alike letter:
0toO,1toI,5toS,8toB. Any other digit in these positions makes the plate"INVALID". - The last three characters must be digits. A letter found there is replaced by its look-alike digit:
Oto0,Ito1,Sto5,Bto8. Any other letter in these positions makes the plate"INVALID".
Positions matter: a B among the first three characters stays B, and an 8 among the last three stays 8.
Input: scan, a string (possibly empty).
Output: the plate as LLL-DDD, or "INVALID".
Example 1
- Input:
- ["kq8 - 4o7"]
- Output:
- "KQB-407"
- Explanation
- Removing the separators and upper-casing gives
KQ84O7, six characters. In the letter positions K and Q are fine and the 8 becomesB. In the digit positions the 4 is fine, theObecomes0and the 7 is fine:KQB-407.
Example 2
- Input:
- ["2xy 905"]
- Output:
- "INVALID"
- Explanation
- After cleaning,
2XY905is six characters, but the first character is a 2, a digit among the letter positions with no look-alike letter, so the plate is invalid.
Example 3
- Input:
- ["O1I.0I5"]
- Output:
- "OII-015"
- Explanation
- The cleaned scan is
O1I0I5. The leadingOis already a letter; the1becomesI; theIstays. In the digit positions the0stays, theIbecomes1and the5stays.
Constraints
0 <= scan.length <= 60scancontains only ASCII letters and digits, plus separator characters from-._*/