1-bit and 2-bit Characters

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
We have two special characters:
The first character can be represented by one bit
0.The second character can be represented by two bits (
10or11).
Given a binary array bits that ends with 0, return true if the last character must be a one-bit character.
LeetCode Problem - 711
class Solution {
// Method to determine if the last character is a one-bit character
public boolean isOneBitCharacter(int[] bits) {
// Initialize an index variable
int i = 0;
// Traverse through the bits array
while (i < bits.length) {
// If the current bit is 0 and it's the last bit, return true
if (bits[i] == 0 && i == (bits.length - 1))
return true;
// If the current bit is 1, skip the next bit
if (bits[i] == 1)
i += 2;
// Otherwise, move to the next bit
else
i += 1;
}
// If traversal completes without encountering the last bit, return false
return false;
}
}




