Search⌘ K
AI Features

DIY: UTF-8 Validation

Explore how to determine the validity of UTF-8 byte sequences by writing a function in Swift. Understand the encoding rules for different byte-length characters and apply this knowledge to solve practical cyber security problems.

Problem description

Given an integer array data, return whether it is a valid UTF-8 encoding.

A character in UTF8 can be from 1 to 4 bytes long, subject to the following rules:

  • For a 1 byte character, the first bit of the packet is 0, followed by its Unicode code.
  • For an n-bytes character, the first
...