Optimal Partition of 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.
Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.
Return the minimum number of substrings in such a partition.
Note that each character should belong to exactly one substring in a partition.
LeetCode Problem - 2405
class Solution {
public int partitionString(String s) {
Set<Character> seenChars = new HashSet<>(); // Set to track characters seen in the current substring
int numOfSubstrings = 1; // Initialize the count of substrings to 1
// Iterate through each character in the string
for (char c : s.toCharArray()) {
// If the character has already been seen in the current substring
if (seenChars.contains(c)) {
// Increment the count of substrings
numOfSubstrings++;
// Clear the set to start tracking characters for the new substring
seenChars.clear();
}
// Add the current character to the set
seenChars.add(c);
}
// Return the total number of substrings
return numOfSubstrings;
}
}




