private static <T> void checkParameters(List<T> list, int k) throws IllegalArgumentException {
        if (list == null) {
            throw new IllegalArgumentException("List can't be null");
        }
        if (k < 0 || k > list.size()) {
            throw new IllegalArgumentException("n can't be negative or larger than the size of the list");
        }
    }