Suppose I have a list of strings where each string is
For each of these strings I wan
This problem can be solved by trie, or prefix tree.
See Trie - Wikipedia, the free encyclopedia
For the 3 strings in your example:
abcd
abcc
bbcb
will be turned into a trie tree (where ^ denotes the root of the tree):
^--a-b-c-d
\ \
\ c
\
b-b-c-b
The path to the node where it branch off are the common prefix. The node after the last branch point is what makes a particular string unique. In this case, they are d, c, b.
I assume the order of string is not important for you, that you compares all strings to find the uniqueness, not just the neighboring string.
The complexity should be O(n x m). But this will probably affected by the domain of the characters in your string.