# Sequence LCS

`sequence-lcs` · version 1.0.0 · Sequences & diffs · free, no key needed

Compute the longest common subsequence of two bounded sequences from the Myers shortest edit script.

**Use when you need to: sequence lcs · longest common subsequence of two sequences · sequence longest common subsequence.**

## Supported

- sequence lcs
- longest common subsequence of two sequences
- sequence longest common subsequence

## Not supported

- longest common substring
- fuzzy matching
- unicode normalization
- patience diff
- histogram diff
- locale compare

## Behavior

- left and right are sequences of JSON null, boolean, string, or IEEE-754 safe integer items.
- Item equality is JavaScript === after validation; there is no case folding, locale compare, or Unicode normalization.
- The LCS is the keep-op values of the Myers shortest edit script, in left order, with parallel index arrays.
- When two Myers D-paths tie, the library prefers a delete from the left sequence.
- For left ["A","B"] and right ["B","A"] the LCS is ["B"] with left_indices [1] and right_indices [0].
- length equals items.length. Empty sequences yield empty arrays and length 0.
- The string "__proto__" is an ordinary item. Unknown input fields are rejected.

## Input

- `left` (array of null or boolean or string or integer, required): max items 1024
- `right` (array of null or boolean or string or integer, required): max items 1024

## Output

- `items` (array of null or boolean or string or integer, required): max items 1024
- `left_indices` (array of integer, required): each min 0
- `right_indices` (array of integer, required): each min 0
- `length` (integer, required): min 0

## Limits

- max sequence items: 1024
- max item string bytes: 4096
- max text bytes: 262144
- max output bytes: 1048576

## Example

Request input:

```json
{
  "left": [
    "A",
    "B",
    "C"
  ],
  "right": [
    "A",
    "X",
    "C"
  ]
}
```

Response:

```json
{
  "result": {
    "items": [
      "A",
      "C"
    ],
    "left_indices": [
      0,
      2
    ],
    "right_indices": [
      0,
      2
    ],
    "length": 2
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "sequence-lcs",
  "version": "1.0.0",
  "input": {
    "left": [
      "A",
      "B",
      "C"
    ],
    "right": [
      "A",
      "X",
      "C"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/sequence-lcs/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"left":["A","B","C"],"right":["A","X","C"]}'
```

The machine-readable contract is at [/v1/tools/sequence-lcs/versions/1.0.0](/v1/tools/sequence-lcs/versions/1.0.0).

### CLI

```sh
node cli.mjs run sequence-lcs 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Sequence longest common substring](/tools/sequence-lcsubstring): Find the longest contiguous common subarray of two bounded sequences.
- [Sequence edit script](/tools/sequence-edit-script): Compute the Myers shortest edit script between two bounded sequences, with keep/delete/insert counts.
- [Sequence three way merge](/tools/sequence-three-way-merge): Three-way merge two sequence descendants against a shared base into clean or conflict regions.
- [Sequence compose edit scripts](/tools/sequence-compose-edit-scripts): Compose two sequence edit scripts into one per-item keep/delete/insert script.
- [Sequence apply edit script](/tools/sequence-apply-edit-script): Apply a keep/delete/insert edit script to a bounded sequence with exact value matching and no fuzz.
- [Sequence apply hunks](/tools/sequence-apply-hunks): Apply disjoint original-address sequence hunks with exact context and no fuzz.
