2716. Minimize String Length#

Approach

As given string contains only lowercase english letters, we can have an array of size 26 and keeping track of the count and counting characters not seen already.

 1public int minimizedStringLength(String s) {
 2  int[] charCount = new int[26];
 3  int length = 0;
 4
 5  for (int i = 0; i < s.length(); i++) {
 6    if (charCount[s.charAt(i) - 'a'] == 0) {
 7      charCount[s.charAt(i) - 'a']++;
 8      length++;
 9    }
10  }
11
12  return length;
13}