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

OpenersNotesSection(Spacer1)Details and Options

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

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

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Find the longest contiguous subsequence common to two strings:

LongestCommonSubsequence[ "AAABBBBCCCCC", "CCCBBBAAABABA"]

Find the longest contiguous subsequence common to two lists:

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

OpenersExampleSection2(Spacer1)Applications  (1)

Longest contiguous DNA subsequence of two genes:

LongestCommonSubsequence[GenomeData["BRCA1"],GenomeData["SCNN1A"]]

OpenersExampleSection3(Spacer1)Neat Examples  (1)

Lengths of the longest common subsequences in random binary sequences of length 1000:

Table[Length[LongestCommonSubsequence[RandomInteger[1,1000],RandomInteger[1,1000]]],{20}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LongestCommonSequence, paclet:ref/LongestCommonSequence])  ▪  (RefLink[SequenceAlignment, paclet:ref/SequenceAlignment])  ▪  (RefLink[NeedlemanWunschSimilarity, paclet:ref/NeedlemanWunschSimilarity])  ▪  (RefLink[Longest, paclet:ref/Longest])  ▪  (RefLink[Subsequences, paclet:ref/Subsequences])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Sequence Alignment & Comparison, paclet:guide/SequenceAlignmentAndComparison])}, {▪(RefLinkPlain[Math & Counting Operations on Lists, paclet:guide/MathematicalAndCountingOperationsOnLists])}, {▪(RefLinkPlain[String Manipulation, paclet:guide/StringManipulation])}, {▪(RefLinkPlain[Text Analysis, paclet:guide/TextAnalysis])}})}})