Category 10 — String Search & Similarity

Longest Common Substring / Subsequence

Find the longest shared contiguous substring or non-contiguous subsequence between two strings.

How to use this tool

  1. Pick a mode with the tabs: Substring (contiguous) finds consecutive shared characters, while Subsequence (non-contiguous) finds characters in order but with gaps allowed.
  2. Type or paste two strings into String A and String B — results update live as you type.
  3. Read the Results panel: it shows the match itself, its Length, both String lengths, and a Coverage percentage.
  4. The highlighted view marks every matched character inside each string, so you can see exactly where the shared region sits.
  5. Click Copy LCS to copy the match to your clipboard, or load a sample like AGGTAB / GXTXAYB with one click.

Why this tool is helpful

Understand diff & merge

Classic diff and three-way merge tools are built on the longest common subsequence. Computing it by hand shows the core idea those tools rely on.

Spot duplicated or copied text

A long common substring between two strings is a strong signal of shared content — useful for spotting copied code or boilerplate duplication.

Work with biological sequences

DNA, RNA, and protein alignment uses longest-common-subsequence ideas. Compare sequences like AGGTAB and GXTXAYB to measure similarity.

Reason about file versions

Seeing how two versions of a string overlap helps you understand what changed, what stayed the same, and how a patch gets produced.

Debug shared substrings

When two outputs share an unexpected chunk, the longest common substring pinpoints the shared region and its exact positions fast.

Stay private

Everything runs in your browser. Nothing is uploaded, logged, or sent to a server — safe for sensitive strings and data.

FAQ

What's the difference between a substring and a subsequence?

A substring must be contiguous — characters appear back-to-back. A subsequence only needs characters to appear in the same order, with gaps allowed. For example, abc is a substring, while ace is a subsequence that skips characters.

Is the result always unique?

No. Two strings can have multiple matches of the same length. The tool returns one of them deterministically — the first longest match it finds — rather than every possible one.

How does it compute the answer?

Both modes use dynamic programming over an m × n table, where m and n are the string lengths, running in O(m × n) time and space.

What does "Coverage" mean?

Coverage is the match length divided by the longer string's length, shown as a percentage. It's a quick measure of how much the two strings overlap.

Is it case-sensitive? What about spaces?

Yes, comparison is exact and case-sensitive, so A and a are treated as different characters, and spaces count as regular characters too.

Can it handle very long strings?

Both algorithms use an m × n table, so memory grows with the product of the two lengths. Very long strings (tens of thousands of characters) may become slow or memory-heavy.

Does any of my data leave my browser?

Never. All computation happens locally in JavaScript. Your input is not sent to, stored on, or logged by any server.