For this Question: You are given an array of length N and an integer K. The array will contain integers numbered through 1 to K. Your task is to calculate the maximum length of the subarray containing  not more than K-1 distinct numbers(atleast one number which does not occur in the subarray)The first line  contains two integers N and K
The second line contains N space-separated integers 

Constraints

1<=K , N<=100000
1<=A[I]<=100000Print a single line containing one integer ― the maximum length of a valid subsegment.Sample Input
6 2
1 1 1 2 2 1


Sample output:-
3


Sample Input:-
5 3
1 1 2 2 1


Sample Output:-
5, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str[]=br.readLine().split(" ");
		int n=Integer.parseInt(str[0]);
		int k=Integer.parseInt(str[1]);
		int a[]=new int[n];
		int m=k-1;
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){
			a[i]=Integer.parseInt(str[i]);
		}
		int b[]=new int[100001];

		long cnt=0;
		int low=0,p=0,q=0;
		for(int i=0;i<n;i++){
			b[a[i]]++;

			if(b[a[i]]==1)
				cnt++;

			while(cnt>m){
				b[a[low]]--;

				if(b[a[low]]==0)
					cnt--;

				low++;
			}
			if((i-low+1)>=(q-p+1)){
				q=i;
				p=low;
			}
		}
		System.out.println(q-p+1);
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?