From a87ef460d2688c6b45c7c08cf34443172934192b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Garc=C3=ADa?= Date: Thu, 30 Oct 2025 18:23:27 -0700 Subject: [PATCH 1/5] Fix code and tests to match problem definition of returning the Kth to last item in the linked list --- .vscode/settings.json | 7 +++++++ chapter_02/p02_return_kth_to_last.py | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..3e99ede3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "." + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/chapter_02/p02_return_kth_to_last.py b/chapter_02/p02_return_kth_to_last.py index 009d0024..eb9a9567 100644 --- a/chapter_02/p02_return_kth_to_last.py +++ b/chapter_02/p02_return_kth_to_last.py @@ -6,7 +6,7 @@ def kth_to_last(ll, k): count = 0 while leader: - if count >= k: + if count >= k + 1: follower = follower.next count += 1 leader = leader.next @@ -24,7 +24,7 @@ def helper(head, k): return None helper_node = helper(head.next, k) counter = counter + 1 - if counter == k: + if counter == k + 1: return head return helper_node @@ -33,8 +33,8 @@ def helper(head, k): test_cases = ( # list, k, expected - ((10, 20, 30, 40, 50), 1, 50), - ((10, 20, 30, 40, 50), 5, 10), + ((10, 20, 30, 40, 50), 0, 50), + ((10, 20, 30, 40, 50), 4, 10), ) From 8a2fad90b2fe3208a6d48e7dc0a185b5b5be989c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Garc=C3=ADa?= Date: Thu, 30 Oct 2025 18:25:32 -0700 Subject: [PATCH 2/5] Delete settings.json file --- .vscode/settings.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 3e99ede3..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "python.testing.pytestArgs": [ - "." - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true -} \ No newline at end of file From 55941f0f6172b2f93d5d051b096a658fa4337645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Garc=C3=ADa?= Date: Thu, 30 Oct 2025 18:27:49 -0700 Subject: [PATCH 3/5] Delete .vscode/settings.json --- .vscode/settings.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 3e99ede3..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "python.testing.pytestArgs": [ - "." - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true -} \ No newline at end of file From a357930ac08c1ff9083baeb028dc058a4b327ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Garc=C3=ADa?= Date: Thu, 30 Oct 2025 18:46:09 -0700 Subject: [PATCH 4/5] Revert "Fix code and tests to match problem definition of returning the Kth to last item in the linked list" This reverts commit a87ef460d2688c6b45c7c08cf34443172934192b. --- chapter_02/p02_return_kth_to_last.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chapter_02/p02_return_kth_to_last.py b/chapter_02/p02_return_kth_to_last.py index eb9a9567..009d0024 100644 --- a/chapter_02/p02_return_kth_to_last.py +++ b/chapter_02/p02_return_kth_to_last.py @@ -6,7 +6,7 @@ def kth_to_last(ll, k): count = 0 while leader: - if count >= k + 1: + if count >= k: follower = follower.next count += 1 leader = leader.next @@ -24,7 +24,7 @@ def helper(head, k): return None helper_node = helper(head.next, k) counter = counter + 1 - if counter == k + 1: + if counter == k: return head return helper_node @@ -33,8 +33,8 @@ def helper(head, k): test_cases = ( # list, k, expected - ((10, 20, 30, 40, 50), 0, 50), - ((10, 20, 30, 40, 50), 4, 10), + ((10, 20, 30, 40, 50), 1, 50), + ((10, 20, 30, 40, 50), 5, 10), ) From a9a4a3f88036b442ca949458f4716da4d9f232aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Garc=C3=ADa?= Date: Thu, 30 Oct 2025 18:58:54 -0700 Subject: [PATCH 5/5] fix(C02_P02): fix code to match problem description --- chapter_02/p02_return_kth_to_last.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chapter_02/p02_return_kth_to_last.py b/chapter_02/p02_return_kth_to_last.py index 009d0024..eb9a9567 100644 --- a/chapter_02/p02_return_kth_to_last.py +++ b/chapter_02/p02_return_kth_to_last.py @@ -6,7 +6,7 @@ def kth_to_last(ll, k): count = 0 while leader: - if count >= k: + if count >= k + 1: follower = follower.next count += 1 leader = leader.next @@ -24,7 +24,7 @@ def helper(head, k): return None helper_node = helper(head.next, k) counter = counter + 1 - if counter == k: + if counter == k + 1: return head return helper_node @@ -33,8 +33,8 @@ def helper(head, k): test_cases = ( # list, k, expected - ((10, 20, 30, 40, 50), 1, 50), - ((10, 20, 30, 40, 50), 5, 10), + ((10, 20, 30, 40, 50), 0, 50), + ((10, 20, 30, 40, 50), 4, 10), )