From e08a6916305a2f6b2ee95badd1da2503da4d805f Mon Sep 17 00:00:00 2001 From: ayaanrizv <66327527+ayaanrizv@users.noreply.github.com> Date: Tue, 23 Mar 2021 19:38:07 +0530 Subject: [PATCH] Update all_construct.py the output when printed should have the elements in the correct order so as we come out of recursions the word should be first and then the suffix_ways elements should come. --- Python/Dynamic_Programming/all_construct.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/Dynamic_Programming/all_construct.py b/Python/Dynamic_Programming/all_construct.py index a85029e..7888912 100644 --- a/Python/Dynamic_Programming/all_construct.py +++ b/Python/Dynamic_Programming/all_construct.py @@ -11,7 +11,7 @@ def all_construct(target, word_bank): if len(target) >= len(word) and target[: len(word)] == word: suffix = target[len(word) :] suffix_ways = all_construct(suffix, word_bank) - target_ways = [way + [word] for way in suffix_ways] + target_ways = [[word] + way for way in suffix_ways] if target_ways: result.extend(target_ways) return result @@ -31,7 +31,7 @@ def helper(target, word_bank): if len(target) >= len(word) and target[: len(word)] == word: suffix = target[len(word) :] suffix_ways = helper(suffix, word_bank) - target_ways = [way + [word] for way in suffix_ways] + target_ways = [[word] + way for way in suffix_ways] if target_ways: result.extend(target_ways) memo[target] = result