I would recommend you draw out some examples and think through how you'd figure it out in your head. Write out the process you go through for each step, and you'll have an algorithm that you can then...