A few hints (another take to make you think and compare with Mark ’s suggestions. Ideally, try to implement both, that’s the best way to learn!
This is a nice exercise to think about because soo many different solutions are possible. Some will be efficient, some will be easier to code, some easier to read and understand. Trying to find different solutions to address this will help you decide which tradeoff is the best for you in this case.