So, I am trying to solve the following problem:
I would solve it this way:
G
where each vertex represents a letter from the alphabet.v1
to v2
into G
iff there exist two words in the given sequence such that w1
= prefix v1 suffix1
, w2
= prefix v2 suffix2
and w1
precedes w2
in the given sequence. You should figure out how to make this step efficient. I believe it can be done in O(sum over a length of each word)
G
can be sorted topologicaly.