MCPcopy Index your code
hub / github.com/keon/algorithms / remove_min

Function remove_min

algorithms/stack/remove_min.py:17–44  ·  view source on GitHub ↗

Remove the minimum value from the stack. Args: stack: A list representing a stack (bottom to top). Returns: The stack with the minimum value removed. Examples: >>> remove_min([2, 8, 3, -6, 7, 3]) [2, 8, 3, 7, 3]

(stack: list[int])

Source from the content-addressed store, hash-verified

15
16
17def remove_min(stack: list[int]) -> list[int]:
18 """Remove the minimum value from the stack.
19
20 Args:
21 stack: A list representing a stack (bottom to top).
22
23 Returns:
24 The stack with the minimum value removed.
25
26 Examples:
27 >>> remove_min([2, 8, 3, -6, 7, 3])
28 [2, 8, 3, 7, 3]
29 """
30 storage_stack: list[int] = []
31 if len(stack) == 0:
32 return stack
33 minimum = stack.pop()
34 stack.append(minimum)
35 for _ in range(len(stack)):
36 val = stack.pop()
37 if val <= minimum:
38 minimum = val
39 storage_stack.append(val)
40 for _ in range(len(storage_stack)):
41 val = storage_stack.pop()
42 if val != minimum:
43 stack.append(val)
44 return stack

Callers 1

test_remove_minMethod · 0.90

Calls 1

popMethod · 0.45

Tested by 1

test_remove_minMethod · 0.72