The secret of the derailleur:
They have a listed capacity, in teeth. To find out what you need, you take the difference between the largest/smallest cassette sprocket, and add that to the same from the chainrings, if there are multiple.
Ex: (42-11)+(36-36)=31. Your derailleur needs to have a capacity of at least 31 teeth...though Shimano is conservative with their numbers, so you would be able to fudge a couple of teeth, at least.