private int[] buildArray(int[] arr, int deleted) {
        int[] result = new int[arr.length - 1];
        for (int i = 0, j = 0; i < arr.length; ++i)
            if (i != deleted) {
                result[j++] = arr[i];
            }
        return result;
    }