Removing Stars From a 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.
You are given a string s, which contains stars *.
In one operation, you can:
Choose a star in
s.Remove the closest non-star character to its left, as well as remove the star itself.
Return the string after all stars have been removed.
Note:
The input will be generated such that the operation is always possible.
It can be shown that the resulting string will always be unique.
LeetCode Problem - 2390
class Solution {
public String removeStars(String s) {
StringBuilder sb = new StringBuilder(s); // Create a StringBuilder object to modify the string
for (int i = 0; i < sb.length(); i++) {
// If the current character is '*'
if (sb.charAt(i) == '*') {
// Remove the '*' character and the character before it
sb.deleteCharAt(i); // Remove the '*' character
sb.deleteCharAt(i - 1); // Remove the character before '*'
i -= 2; // Move the index back by 2 to account for the removed characters
}
}
// Convert the modified StringBuilder back to a string and return it
return sb.toString();
}
}




