What if I saved a character mapping for each character set and then incremented that count every time ...
For the first set ( ZBANICOT ), this will create the following pairs of characters (28 of them):
ZB, ZA, ZN, ZI, ZC, ZO, ZT BA, BN, BI, BC, BO, BT AN, AI, AC, AO, AT NI, NC, NO, NT IC, IO, IT CO, CT OT
For the second set ( ACNTBZIO ) I will have 28 pairs again:
AC, AN, AT, AB, AZ, AI, AO CN, CT, CB, CZ, CI, CO NT, NB, NZ, NI, NO TB, TZ, TI, TO BZ, BI, BO ZI, ZO IO
For the last two sets, I would:
AN, AI, AC, AO, AT, AZ, AB NI, NC, NO, NT, NZ, NB IC, IO, IT, IZ, IB CO, CT, CZ, CB OT, OZ, OB TZ, TB ZB ZI, ZA, ZN, ZC, ZO, ZT, ZB IA, IN, IC, IO, IT, IB AN, AC, AO, AT, AB NC, NO, NT, NB CO, CT, CB OT, OB TB
(So, to determine the iteration counter so far, let N be the number of sets and M number of characters in each set, in this example we have N*(M)((M-1)/2) or 4*28=112 )
Next, I would count the number of times each pair exists. For instance,
PairCounts["ZB"] == 3 PairCounts["ZA"] == 2 // ... PairCounts["AO"] == 4 PairCounts["AT"] == 4 // ... PairCounts["AN"] == 4 PairCounts["AC"] == 4 PairCounts["CT"] == 4 PairCounts["NO"] == 4 PairCounts["NT"] == 4
Then, since we have 4 pairs, I would drop all pairs that did not have the number 4. And then I would try to match each pair to form the longest line.