Delete Characters to Make Fancy String

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.
A fancy string is a string where no three consecutive characters are equal.
Given a string s, delete the minimum possible number of characters from s to make it fancy.
Return the final string after the deletion. It can be shown that the answer will always be unique.
LeetCode Problem - 1957
class Solution {
public String makeFancyString(String s) {
// StringBuilder to build the resulting string
StringBuilder sb = new StringBuilder();
// Variable to track the count of consecutive identical characters
int count = 1;
// Loop through each character in the string
for (int i = 0; i < s.length(); i++) {
char currChar = s.charAt(i); // Get the current character
// If the current character is the same as the previous one, increment the count
if (i > 0 && currChar == s.charAt(i - 1)) {
count++;
} else {
// If the current character is different, reset the count to 1
count = 1;
}
// Append the character to the result if it appears 2 or fewer times consecutively
if (count <= 2) {
sb.append(currChar);
}
}
// Return the resulting string
return sb.toString();
}
}




