Trains the technique from
LeetCode 1092Shortest Common SupersequenceThis 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 readings of lowercase letters are given, first and second. A tape holds a reading when deleting some of the tape's letters, possibly none of them, leaves that reading exactly.
Return the shortest tape that holds both readings. Where several tapes tie for shortest, return the one that comes first in dictionary order.
Example 1
The tape holds the first reading once its opening letter is dropped and the second once its closing letter is dropped. Nothing shorter works, since the two readings share only the letters b and c.
Example 2
The two readings share no letter at all, so the tape has to hold all six. Writing the first reading before the second comes earlier in dictionary order than the other way round.
Example 3
Three letters are needed, since the readings share only one letter in common. Both possible tapes work, and the one opening on a comes first in dictionary order.
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 shortest_common_supersequence(first: str, second: str) -> str:public String shortestCommonSupersequence(String first, String second)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.