javascript advanced מסתיים ב-2026-11-24

Line diff (longest common subsequence)

Write diffLines(a, b) that compares two arrays of lines and returns an edit script: an array of [op, line] pairs where op is "=" (in both), "-" (only in a) or "+" (only in b).

  • Keeping the "=" lines must give the longest common subsequence, so the diff is as small as possible.
  • Taking "=" and "-" lines in order rebuilds a; taking "=" and "+" lines rebuilds b.
  • Arrays up to a few hundred lines must finish quickly (dynamic programming, O(n·m)).

Acceptance criteria

  • The tests at the bottom print All tests passed.

נפתר עד כה על ידי 0 אנשים.

javascript
עורךCtrl + Enter

            
        

כשהבדיקות מדפיסות "All tests passed", האתגר מסומן כפתור בדפדפן הזה.

שליחת הפתרון לבדיקה