Here is a challenge for the experts I believe.
Data:
I have different strings S1: ABCF; S2: DABAF; S3: BACF
Then I have a different string B1: DABACF. You can notice that string B1 contains all the letters from string S1, S2 and S3.
What I need to do is take the first strings (S1, S2, S3) and count the ¨moves¨ in string B1. The starting point in B1 would be letter D (1) and the finishing point letter F.
For example S1: ABCF B1: DABACF
TO count the moves of S1 in B1 I would count the moves as followed. Moves: (LocationLetter - PreviousLocation)+ OldMoves
Location Letter ¨A¨ of S1 in string B1 is 2. Moves: (2-0) +0= 2. OldMoves= Moves. PreviousLocation= LocationLetter
Location Letter ¨B¨ of S1 in string B1 is 3. Moves: (3-2)+2= 3. OldMoves= Moves. PreviousLocation= LocationLetter
Location Letter ¨C¨ of S1 in string B1 is 5. Moves: (5-3)+3= 5. OldMoves= Moves. PreviousLocation= LocationLetter
Location Letter ¨F¨ of S1 in string B1 is 6. Moves: (6-5)+5= 6.
That means the total moves to go from left to right were 6 for S1.
If you do the same with S2: DABAF . The total moves you will also get 6.
In the previous 2 examples even though we have repeated letters in B1:DABACF I only considered the first one that appears from left to right. If I would have selected the second letter it would have given me more moves and that is something I do not want. I would like to be able to recognize the position of repeated letters and also performed the calculation and at the end select the min.
In the third example S3: BACF notice that to make the less amount of moves through B1: DABACF it would better to select the second A instead of the first one.
In conclusion what I am trying to figure out is the minimum amount of "moves" for strings (S1, S2, S3) to go through another string (B1) taking into account repeated characters.
Let me know if you come with an idea.
Thank you,
Maria
Bookmarks