posted 2 years ago
Do you have a specific question? Vague questions get vague answers.
Q: How can I solve this problem as a program?
A: Write a program to solve it.
We're not going to hand out answers to homework problems. Nobody here will just write the code for you. Besides, if they did, you'd get in trouble for academic dishonesty.
What SPECIFIC questions do you have? Where EXACTLY are you stuck?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors