Trains the technique from
LeetCode 1143Longest Common SubsequenceThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two field technicians walked the same plant during one shift. Each kept a personal log of the maintenance checkpoints they signed off, written in the order they signed them. Every checkpoint is identified by a single lowercase letter, and a technician may sign the same checkpoint again later in the shift.
Call a trace of a log whatever is left once you erase any number of its entries, including erasing nothing at all; the entries you keep stay in the sequence they were written.
Given the logs logA and logB, report how many entries the longest trace that occurs in both logs contains. Two logs that have no letter in common yield 0.
Example 1
Erase the leading `p` from the first log and you are left with `urge`; those same four checkpoints sit in that order inside `urgent`.
Example 2
The two technicians never touched the same checkpoint, so the longest trace they both hold is empty.
Example 3
All three entries of the first log reappear in order inside the second, even though `a` and the two `r` entries sit between them.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def longest_shared_trace(logA: str, logB: str) -> int:public int longestSharedTrace(String logA, String logB)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.