public static int[] findKClosest(int[] input, int k, int x ){
        //find the crossover index which is less than or equals to the x
        int crossoverIndex = findCrossover(input, x, 0 , input.length-1);
        //declare the result array
        int [] result = new int[k];
        //fill the crossover as first result
        result[0] = input[crossoverIndex];

        int resultAccumulated = 1;
        int indexLeft = crossoverIndex -1;
        int indexRight = crossoverIndex +1;
        // like merge sort
        while(resultAccumulated!=k && indexLeft>=0 && indexRight<input.length){
            //get the closesr distance element from either left or right
            result[resultAccumulated++] =  Math.abs(input[indexLeft]-x) < Math.abs(input[indexRight]-x)? input[indexLeft--]: input[indexRight++];
        }

        while(resultAccumulated<k){
            //put elements from either left or right subarray which ever has capacity left
            result[resultAccumulated++] = indexLeft>=0 ? input[indexLeft--] : input[indexRight++];

        }


        return result;

    }