I have to find a cost optimal solution for staying on campsites.
It is kind of weigthed interval scheduling with a given number of intervals (nights).
I wonder how to tackle it, dynamic programmic will work for cost optimizatation gernerally but how to build in the restriction on the number of intervalls?

So i can pick for example 4 out of a list C=[0,10,23,30,45,78,95,100]; the larger the distance the higher the cost. How can i interval schedule with given n intervals?

Still not getting the problem. Set up your dynamic solver. Have it run. If it ever gets to a solution that has more than n parts, reject that as a solution. If it ever gets to a point where there are no more choices and it is less than n, reject that as a solution.

You could just generate all the combinations for this as there are only 1680 to check, and it would be faster than doing a dynamic solution.

Brute force solution is unlikely to be the assignment for an algorithm class. besides you can only choose intervals that touch so you have to strat where you left th enight before.

So the method remove removes only the first occurrence of an element. I am supposed to Add the method
removeAll() that will remove all occurrences of a given element. I ...

Over the years I've seen a lot of discussion (and several implementations) of the Quicksort algorithm. Most of what I have seen, unfortunately, lacks sufficient commenting as well as meaningful ...