Quote:
I have no idea how to solve this
First, you need to understand the problem. The only way is to solve repeatedly the problem by hand with different examples, invent some sample data as you need to cover all cases.
So, take a sheet of paper and pencil, then try to solve the problem by hand.
It is a trial and error process, this is how you will learn.
Problem analyze is a skill you will gain by experience, we can't teach you experience.
In your case, experience comes as you have solved many kinds of problems and when you detect similarities with previous problems, because chances are that the solution is similar too.
- Learn one or more analyze methods, E.W. Djikstra/N. Wirth
Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[
^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[
^]
https://en.wikipedia.org/wiki/Structured_programming[
^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[
^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[
^]
- Learn Algorithms and Data-Structures.
Dynamic programming - Wikipedia[
^]