Company: Axis_bank_22nov
Difficulty: medium
Fixed Window Problem Description You are given a string S of length n consisting of lowercase English letters, and an integer K . Find the largest length L such that every contiguous substring of S of length L contains at most K distinct characters. A substring is a contiguous sequence of characters within a string. Function Description Implement the function largestSubarray : input1 ( int n ): the length of S input2 ( int K ): the maximum number of distinct characters allowed in a window input3 ( String S ): the string, of length exactly n The function returns an integer: the largest valid length L . Input Format For custom testing, standard input contains three lines: Line 1: the integer n Line 2: the integer K Line 3: the string S Output Format Print a single integer: the largest valid length L . Examples Example 1 Input 9 2 baaabbcca Output 3 Explanation: every window of length 3 holds at most 2 distinct characters, but the window abbc ( S[3..6] ) of length 4 holds 3, so L = 3 . Ex