Report Spam Message

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 an array of strings message and an array of strings bannedWords.
An array of words is considered spam if there are at least two words in it that exactly match any word in bannedWords.
Return true if the array message is spam, and false otherwise.
LeetCode Problem - 3295
class Solution {
public boolean reportSpam(String[] message, String[] bannedWords) {
// Create a set from the banned words for faster lookup
Set<String> bannedWordSet = new HashSet<>(Arrays.asList(bannedWords));
int flag = 0; // Initialize a counter to track the number of banned words found
for (String str : message) {
// Check if the current word is in the set of banned words
if (bannedWordSet.contains(str)) {
flag++; // Increment the counter if a banned word is found
}
// If two or more banned words are found, report as spam
if (flag == 2) return true;
}
// If fewer than two banned words are found, return false
return false;
}
}




