private static int searchInArray(int[] array, int key)
    {
        int low = 0;
        int high = array.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (array[mid] == key)
                return mid;
            else if (mid > 0 && array[mid - 1] == key)
                return mid - 1;
            else if (mid <= array.length - 1 && array[mid + 1] == key)
                return mid + 1;
            else if (array[mid] > key)
                high = mid - 2;
            else if (array[mid] < key)
                low = mid + 2;
            else return -1;
        }
        return -1;
    }