From c93a546c9620035e9c85a9e9c3bfebc15c5dc76f Mon Sep 17 00:00:00 2001 From: Mohamed Vadhel Ebnou Oumar Date: Sun, 24 May 2026 11:30:45 +0200 Subject: [PATCH] fix: tighten loop bound in first_switch_pairs --- algorithms/stack/switch_pairs.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/algorithms/stack/switch_pairs.py b/algorithms/stack/switch_pairs.py index ddf2325e6..71062b908 100644 --- a/algorithms/stack/switch_pairs.py +++ b/algorithms/stack/switch_pairs.py @@ -33,9 +33,7 @@ def first_switch_pairs(stack: list[int]) -> list[int]: storage_stack: list[int] = [] for _ in range(len(stack)): storage_stack.append(stack.pop()) - for _ in range(len(storage_stack)): - if len(storage_stack) == 0: - break + for _ in range((len(storage_stack)+1)//2): first = storage_stack.pop() if len(storage_stack) == 0: stack.append(first)