({{, (RefLink[LongestCommonSequence, paclet:ref/LongestCommonSequence])[(Subscript[s, 1]),(Subscript[s, 2])] 
finds the longest sequence of contiguous or disjoint elements common to the strings or lists (Subscript[s, 1]) and (Subscript[s, 2]).}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[LongestCommonSequence, paclet:ref/LongestCommonSequence]) returns the longest common sequence with disjoint pieces concatenated.

If there are several common subsequences of the same length, (RefLink[LongestCommonSequence, paclet:ref/LongestCommonSequence]) returns the one that begins earliest in (Subscript[s, 1]).

For strings, setting the option (RefLink[IgnoreCase, paclet:ref/IgnoreCase])->(RefLink[True, paclet:ref/True]) makes (RefLink[LongestCommonSequence, paclet:ref/LongestCommonSequence]) treat lowercase and uppercase letters as equivalent, and return the form of common sequence that occurs in (Subscript[s, 1]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Find the longest noncontiguous sequence common to two strings:

LongestCommonSequence[ "AAABBBBCCCCC", "CCCBBBAAABABA"]

Find the longest noncontiguous sequence common to two lists:

LongestCommonSequence[{"A","B","C","D"},{"B","C","A","D"}]

OpenersExampleSection2(Spacer1)Neat Examples  (1)

Find the lengths of longest common sequences in random binary sequences of length 100:

Table[Length[LongestCommonSequence[RandomInteger[1,100],RandomInteger[1,100]]],{1000}]//Histogram

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LongestCommonSubsequence, paclet:ref/LongestCommonSubsequence])  ▪  (RefLink[SequenceAlignment, paclet:ref/SequenceAlignment])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Sequence Alignment & Comparison, paclet:guide/SequenceAlignmentAndComparison])}})}})