From 3ef48c18b982afc82aaa90f2662e5b14d59fc5ea Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 30 Jun 2026 17:17:24 +0530 Subject: [PATCH 1/7] Add missing type hints to pancake_sort --- sorts/pancake_sort.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index e5d600738435..0d7318701e94 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -8,8 +8,9 @@ python pancake_sort.py """ +from collections.abc import MutableSequence -def pancake_sort(arr): +def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: """Sort Array with Pancake Sort. :param arr: Collection containing comparable items :return: Collection ordered in ascending order of items From fccd424410402a3c3bb98ee4de9f846f88003e9c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:56:32 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/pancake_sort.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index 0d7318701e94..85f5b669ca98 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -10,6 +10,7 @@ from collections.abc import MutableSequence + def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: """Sort Array with Pancake Sort. :param arr: Collection containing comparable items From 73e64c33ffbe711e2303482c3798281d50f81c84 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 30 Jun 2026 22:09:16 +0530 Subject: [PATCH 3/7] Fix review comments --- sorts/insertion_sort.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 2e39be255df7..9bdb1f9b4ccc 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -13,6 +13,7 @@ python3 insertion_sort.py """ +from __future__ import annotations from collections.abc import MutableSequence from typing import Any, Protocol, TypeVar @@ -48,6 +49,9 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ >>> collection = random.choices(string.ascii_letters + string.digits, k=100) >>> insertion_sort(collection) == sorted(collection) True + + Time Complexity: (O(n^2)) + Space Complexity:(O(n)) """ for insert_index in range(1, len(collection)): @@ -63,7 +67,3 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ from doctest import testmod testmod() - - user_input = input("Enter numbers separated by a comma:\n").strip() - unsorted = [int(item) for item in user_input.split(",")] - print(f"{insertion_sort(unsorted) = }") From c810a25a365eac5cee24a773a5157230c5f0e2a5 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 30 Jun 2026 23:13:58 +0530 Subject: [PATCH 4/7] Address review comments --- sorts/pancake_sort.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index 85f5b669ca98..bf06a59859a7 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -8,6 +8,7 @@ python pancake_sort.py """ +from __future__ import annotations from collections.abc import MutableSequence @@ -22,6 +23,9 @@ def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: [] >>> pancake_sort([-2, -5, -45]) [-45, -5, -2] + + Time Complexity: O(n^2) + Space Complexity: O(n) """ cur = len(arr) while cur > 1: @@ -34,8 +38,6 @@ def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: cur -= 1 return arr - if __name__ == "__main__": - user_input = input("Enter numbers separated by a comma:\n").strip() - unsorted = [int(item) for item in user_input.split(",")] - print(pancake_sort(unsorted)) + import doctest + doctest.testmod() From 559c01eda2f780553ed14d6978e1f3307b32b1c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 17:44:44 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/insertion_sort.py | 2 +- sorts/pancake_sort.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 9bdb1f9b4ccc..157e7ce0216e 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -49,7 +49,7 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ >>> collection = random.choices(string.ascii_letters + string.digits, k=100) >>> insertion_sort(collection) == sorted(collection) True - + Time Complexity: (O(n^2)) Space Complexity:(O(n)) """ diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index bf06a59859a7..961f3c5b2884 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -23,7 +23,7 @@ def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: [] >>> pancake_sort([-2, -5, -45]) [-45, -5, -2] - + Time Complexity: O(n^2) Space Complexity: O(n) """ @@ -38,6 +38,8 @@ def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: cur -= 1 return arr + if __name__ == "__main__": import doctest + doctest.testmod() From e26a317587d7ee8b7a79b2d39b97b89a796159b2 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 30 Jun 2026 23:29:51 +0530 Subject: [PATCH 6/7] Fix ruff formatting issues --- sorts/insertion_sort.py | 1 + sorts/pancake_sort.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 157e7ce0216e..5e85abb4da2e 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -14,6 +14,7 @@ """ from __future__ import annotations + from collections.abc import MutableSequence from typing import Any, Protocol, TypeVar diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index 961f3c5b2884..f95883f7522e 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -9,6 +9,7 @@ """ from __future__ import annotations + from collections.abc import MutableSequence @@ -41,5 +42,4 @@ def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: if __name__ == "__main__": import doctest - doctest.testmod() From 1fc9bc0b3eeb449355291168a30711860554ef8c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:00:09 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/pancake_sort.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index f95883f7522e..2860e0efe1ca 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -42,4 +42,5 @@ def pancake_sort(arr: MutableSequence[int]) -> MutableSequence[int]: if __name__ == "__main__": import doctest + doctest.testmod()