LeetcodeDay 23
LeetcodeDay 23
PseudoCode:-
// Function to check if the concatenated first characters of words form the given acronym
function isAcronym(words: List<String>, s: String) -> boolean:
// Initialize a StringBuilder to store the first characters of each word
StringBuilder sb = new StringBuilder()
PseudoCode:-
PseudoCode:-
// Function to find the lengths of partitions in a string where each letter appears in at most one part
function findPartitionLengths(s: String) -> List of Integer:
// Initialize a HashMap to store the last occurrence index of each character
Map<Character, Integer> map = new HashMap<>();
// Populate the HashMap with the last occurrence index of each character
for i from 0 to length of s - 1:
map.put(s.charAt(i), i);
// Initialize variables to track the maximum index and the start of the current partition
int max = map.get(arr[0]);
int prev = 0;
// Function to partition a string into as many parts as possible, where each letter appears in at
most one part
function partitionLabels(s: String) -> List of Integer:
// Initialize an array to store the last occurrence index of each character in the string
int[] last = new int[26]
// Iterate through the string from right to left to record the last occurrence index of each
character
for i from s.length() - 1 to 0:
char ch = s.charAt(i)
if last[ch - 'a'] == 0:
last[ch - 'a'] = i
// Initialize the character and its last occurrence index for the first partition
char ch = s.charAt(j)
int idx = last[ch - 'a']
// Increment j
j++
// Update the character and its last occurrence index for the next partition
ch = s.charAt(j)
idx = max(idx, last[ch - 'a'])