Utf - 8 Encoding

easy
1. You are given an array of integers.
2. You are required to test whether the array represents a valid sequence of UTF-8 characters or 
     not.
3. A character in UTF-8 can be from 1 to 4 bytes long and follows some rules - 
       (i)  For 1-byte long character, first bit will be 0 and rest represents its unicode code.
       (ii) For n-bytes long character, first n-bits will be 1's, the n+1th bit is 0, followed by n-1 bytes 
             with most significant 2 bits being 10.

Note -> Only the least significant 8 bits of each element in array is used for data.
Note -> Check out the question video for details.

Input Format

A number N arr1 arr2.. N numbers

Output Format

Check the sample output and question video.

Constraints

1 <= n <= 10^9
0 < a[i] <= 255

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
3
197
130
1
Output
true
Previous
Abbreviation 1 - Using Bits
Next
Sudoku Using Bit Manipulation

Related Questions