Fixed Sliding Window
Template
public void method(String s) {
// Create a result set/variable
// Check for edge cases
if(s.length() == 0 || s == null || s.isBlank()) {
// Handle it appropriately or return the result
}
// Create a ds, which is required to hold the data of the window
holder = Map, Set, int[]
int start = 0;
// Iterate it over input
for(int end=0;end<s.length();end++) {
// Get the current element
char ch = s.charAt(end);
// Store the current element desired property in holder
holder.put(ch, freq);
// Check if the given window is valid
// If valid, add the required property (like index, frequency, length) to result set
// Reduce the size of window by moving forward start pointer
}
return result;
}Example Problem:
Last updated