CT074

UTF-8 Validation

MediumAcceptance: 0.0%

UTF-8 is a variable-length character encoding. A 1-byte character starts with 0, a 2-byte with 110, a 3-byte with 1110, a 4-byte with 11110. Continuation bytes start with 10. Given an array of integers representing byte values, determine if it is a valid UTF-8 encoding. Input: first line n, second line n integers. Output "true" or "false".

Example 1:

Input: 3 197 130 1
Output: true

Example 2:

Input: 2 235 140
Output: false

Constraints:

1 <= n <= 10^4 0 <= byte <= 255

Tags:

bit-manipulation validation
Loading...
Test Cases:No test cases
No test cases available.