Suppose I have:
- Toby
- Tiny
- Tory
- Tily
Is there an algorithm that can easily create a list of common characters in the same positions in all these strings? (in this case the common characters are ‘T’ at position 0 and ‘y’ at position 3)
I tried looking at some of the algorithms used for DNA sequence matching but it seems most of them are just used for finding common substrings regardless of their positions.
Finding a list of characters that are common in ALL strings at a certain position is trivially simple. Just iterate on each string for each character position 1 character position at a time. If any string’s character is not the match of it’s closest neighbor string’s character, then the position does not contain a common character.
For any i = 0 to length -1… Once you find Si[x] != Si+1[x] you can skip to the next position x+1.
Where Si is the ith string in the list. And [x] is the character at position x.