Skip to content
Discussion options

You must be logged in to vote

We need to determine if the last character in a binary array (ending with 0) must be a one-bit character. The two valid characters are:

  • One-bit: 0
  • Two-bit: 10 or 11

The key is to traverse the array and decode the characters. If we end exactly at the last bit, it must be a one-bit character. Otherwise, if we skip over the last bit (meaning it was part of a two-bit character), it's not a one-bit character.

Approach:

We'll traverse the array from left to right. When we encounter a 1, it must be the start of a two-bit character, so we skip the next bit. When we encounter a 0, it's a one-bit character, so we move to the next bit. We continue until we reach or pass the last bit. If we land ex…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Nov 18, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants