solution: part c.
We use the same algorithm as in b.