For this Question: Given an array A and an integer K. Find the maximum for each and every contiguous subarray of size K.


Problem asked in Amazon, Flipkart.The first line of each test case contains a single integer N denoting the size of array and the size of subarray K. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.

Constraints:
1 ≤ N ≤ 10^5
1 ≤ K ≤ N
0 ≤ A[i] <= 10^5Print the maximum for every subarray of size K.Sample Input:
9 3
1 2 3 1 4 5 2 3 6

Sample Output:
3 3 4 5 5 5 6

Explanation:
Starting from the first subarray of size k = 3, we have 3 as maximum. Moving the window forward, maximum element are as 3, 4, 5, 5, 5 and 6., I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
    public static void printMax(int arr[], int n, int k) {
        int j, max;

        for(int i = 0; i <= n - k; i++) {
            max = arr[i];

            for(j = 1; j < k; j++) {
                if(arr[i + j] > max) {
                    max = arr[i + j];
                }
            }
            System.out.print(max + " ");
        }
    }

	public static void main (String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str1[] = br.readLine().trim().split(" ");

        int n = Integer.parseInt(str1[0]);
        int k = Integer.parseInt(str1[1]);

        String str2[] = br.readLine().trim().split(" ");
        int arr[] = new int[n];

        for(int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(str2[i]);
        }
        printMax(arr, n ,k);

	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?