From 9023a3c1e765ed4d97a848946b52a524ee5f7db3 Mon Sep 17 00:00:00 2001 From: Shubham Padkonde Date: Fri, 23 Oct 2026 21:50:52 +0530 Subject: [PATCH] Stop Smith-Waterman traceback at zero-score cells --- dynamic_programming/smith_waterman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/smith_waterman.py b/dynamic_programming/smith_waterman.py index 4c5d58379f07..ea46e68fc530 100644 --- a/dynamic_programming/smith_waterman.py +++ b/dynamic_programming/smith_waterman.py @@ -162,7 +162,7 @@ def traceback(score: list[list[int]], query: str, subject: str) -> str: # guard against empty query or subject if i == 0 or j == 0: return "" - while i > 0 and j > 0: + while i > 0 and j > 0 and score[i][j] > 0: if score[i][j] == score[i - 1][j - 1] + score_function( query[i - 1], subject[j - 1] ):