mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-07 18:08:01 +00:00
Polish stack min challenge and solution (#72)
Update constraints, algorithm discussion, code, and tests.
This commit is contained in:
@@ -36,9 +36,13 @@
|
||||
"\n",
|
||||
"* Can we assume this is a stack of ints?\n",
|
||||
" * Yes\n",
|
||||
"* If we call this function on an empty stack, can we return maxsize?\n",
|
||||
"* Can we assume the input values for push are valid?\n",
|
||||
" * Yes\n",
|
||||
"* If we call this function on an empty stack, can we return sys.maxsize?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume we already have a stack class that can be used for this problem?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume this fits memory?\n",
|
||||
" * Yes"
|
||||
]
|
||||
},
|
||||
@@ -91,7 +95,7 @@
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class MyStack(Stack):\n",
|
||||
"class StackMin(Stack):\n",
|
||||
"\n",
|
||||
" def __init__(self, top=None):\n",
|
||||
" # TODO: Implement me\n",
|
||||
@@ -137,7 +141,7 @@
|
||||
"\n",
|
||||
" def test_stack_min(self):\n",
|
||||
" print('Test: Push on empty stack, non-empty stack')\n",
|
||||
" stack = MyStack()\n",
|
||||
" stack = StackMin()\n",
|
||||
" stack.push(5)\n",
|
||||
" assert_equal(stack.peek(), 5)\n",
|
||||
" assert_equal(stack.min(), 5)\n",
|
||||
@@ -188,21 +192,21 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 2",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python2"
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.10"
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user