Nov-04-2022, 04:26 AM
(This post was last modified: Nov-04-2022, 04:26 AM by deanhystad.)
This is a fun problem. I ended up with a recursive solution. I modified the Alex list for brevity
Find where Alex[0] matches John
The trickiest part is you cannot place a tick mark in the match list if the Alex list is not an ordered sub-list of the John list. In addition to an empty Alex list, this signals a break in the recursion.
Find where Alex[0] matches John
Output: John 6 1 1 3 3 6 2 5 4 1 1 3
|
Alex 6 3 2 5
Match 1 0 0 0 0 0 0 0 0 0 0 0
Now find the first match for Alex[1:] and John[1:]Output: John 1 1 3 3 6 2 5 4 1 1 3
|
Alex 3 2 5
Match 1 0 0 1 0 0 0 0 0 0 0 0
And then find the first match for Alex[2:] and John[4:]Output:John 3 6 2 5 4 1 1 3
|
Alex 2 5
Match 1 0 0 1 0 0 1 0 0 0 0 0
This is repeated until the Alex list is empty. When the Alex list is empty you unwind the recursion and find the next match.The trickiest part is you cannot place a tick mark in the match list if the Alex list is not an ordered sub-list of the John list. In addition to an empty Alex list, this signals a break in the recursion.