Skip to content

Practice UTF-8 Validation

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#393
LeetCode Problem

UTF-8 Validation

Problem Statement

Return whether data represents valid UTF-8 byte patterns. A one-byte character starts with bit 0. A character using n bytes, for n from 2 through 4, starts with n one-bits followed by 0; each remaining byte starts with 10. Parse the full sequence into such characters, rejecting missing or unexpected continuation bytes. Only the lowest eight bits of each data value are used.

Source: UTF-8 Validation on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
data = [197,130,1]
Output
true

# Example 2

Input
data = [235,140,4]
Output
false

Constraints

1 <= data.length <= 2 * 10^4
0 <= data[i] <= 255

Related LeetCode Problems

Practice more problems similar to UTF-8 Validation.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.