Skip to content

Instantly share code, notes, and snippets.

View TheRoyalDebugger's full-sized avatar
🏠
Working from home

Dhruv Narayan Singh TheRoyalDebugger

🏠
Working from home
  • AT&T
  • India
View GitHub Profile
@TheRoyalDebugger
TheRoyalDebugger / LongestSubstringKDistinct.java
Created October 12, 2020 08:00 — forked from Schachte/LongestSubstringKDistinct.java
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);