Quote:
I'm stuck on the logic.
This the object of the homework. You have to decipher the logic.
First of all, take a sheet of paper and a pencil, then try to sort out some logic in the example:
- What if list have other numbers?
- What values can have the first number in result list? second? ...
- what was its position in list?
- what if you pick only 1 number? 2? 3?
write the resulting lists.
workout similarities.
This search activity is the base of programming job, as you gain experience, part of the activity is also to check if the logic of the problem is similar to another one where the solving algorithm is known.
If I give you just a full blowup solution, it will be like magic to you and you will learn nothing.