Skip to content

Instantly share code, notes, and snippets.

View kishorekpoluri's full-sized avatar

Kishore K Poluri kishorekpoluri

View GitHub Profile
@Schachte
Schachte / LongestSubstringKDistinct.java
Last active April 14, 2024 06:39
Sliding Window Maximum Sum Subarray
import java.util.*;
class LongestSubstringKDistinct {
public static int findLength(String str, int k) {
int windowStart = 0, maxLength = 0;
Map<Character, Integer> charFrequencyMap = new HashMap<>();
for (int windowEnd = 0; windowEnd < str.length(); windowEnd++) {
char rightChar = str.charAt(windowEnd);
charFrequencyMap.put(rightChar, charFrequencyMap.getOrDefault(rightChar, 0) + 1);