diff --git a/Array Sequences/Amortization.ipynb b/Array Sequences/Amortization.ipynb index d58ff51c..11735889 100644 --- a/Array Sequences/Amortization.ipynb +++ b/Array Sequences/Amortization.ipynb @@ -22,23 +22,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Array Sequences/Array Mini-Project.ipynb b/Array Sequences/Array Mini-Project.ipynb index 1a4dc652..69b99a28 100644 --- a/Array Sequences/Array Mini-Project.ipynb +++ b/Array Sequences/Array Mini-Project.ipynb @@ -23,23 +23,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - PRACTICE/Anagram Check .ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - PRACTICE/Anagram Check .ipynb index eac9c379..0e0c5dd4 100644 --- a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - PRACTICE/Anagram Check .ipynb +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - PRACTICE/Anagram Check .ipynb @@ -205,7 +205,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Anagram Check - SOLUTION.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Anagram Check - SOLUTION.ipynb index 91e7d3d2..a832469f 100644 --- a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Anagram Check - SOLUTION.ipynb +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Anagram Check - SOLUTION.ipynb @@ -302,7 +302,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Find the Missing Element - SOLUTION.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Find the Missing Element - SOLUTION.ipynb index 0b216746..b0691598 100644 --- a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Find the Missing Element - SOLUTION.ipynb +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions - SOLUTIONS/Find the Missing Element - SOLUTION.ipynb @@ -55,9 +55,7 @@ { "cell_type": "code", "execution_count": 46, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -86,9 +84,7 @@ { "cell_type": "code", "execution_count": 44, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "import collections\n", @@ -114,9 +110,7 @@ { "cell_type": "code", "execution_count": 47, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -167,9 +161,7 @@ { "cell_type": "code", "execution_count": 39, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -209,9 +201,7 @@ { "cell_type": "code", "execution_count": 43, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -250,23 +240,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Anagram Check - Tung Practice-checkpoint.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Anagram Check - Tung Practice-checkpoint.ipynb new file mode 100644 index 00000000..66c26bf5 --- /dev/null +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Anagram Check - Tung Practice-checkpoint.ipynb @@ -0,0 +1,187 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Anagram Check\n", + "\n", + "## Problem\n", + "\n", + "Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). \n", + "\n", + "For example:\n", + "\n", + " \"public relations\" is an anagram of \"crap built on lies.\"\n", + " \n", + " \"clint eastwood\" is an anagram of \"old west action\"\n", + " \n", + "**Note: Ignore spaces and capitalization. So \"d go\" is an anagram of \"God\" and \"dog\" and \"o d g\".**\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "def anagram(s1,s2):\n", + " '''\n", + " Tung practice\n", + " '''\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram('dog','god')" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram('clint eastwood','old west action')" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram('aa','bb')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "Run the cell below to test your solution" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class AnagramTest(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol('go go go','gggooo'),True)\n", + " assert_equal(sol('abc','cba'),True)\n", + " assert_equal(sol('hi man','hi man'),True)\n", + " assert_equal(sol('aabbcc','aabbc'),False)\n", + " assert_equal(sol('123','1 2'),False)\n", + " print \"ALL TEST CASES PASSED\"\n", + "\n", + "# Run Tests\n", + "t = AnagramTest()\n", + "t.test(anagram)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "t.test(anagram2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Array Pair Sum - Tung-checkpoint.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Array Pair Sum - Tung-checkpoint.ipynb new file mode 100644 index 00000000..e90291a4 --- /dev/null +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Array Pair Sum - Tung-checkpoint.ipynb @@ -0,0 +1,138 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Array Pair Sum\n", + "\n", + "## Problem\n", + "\n", + "Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**.\n", + "\n", + "So the input:\n", + " \n", + " pair_sum([1,3,2,2],4)\n", + "\n", + "would return **2** pairs:\n", + "\n", + " (1,3)\n", + " (2,2)\n", + "\n", + "**NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS**\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "def pair_sum(arr,k):\n", + " \n", + " my_dict = {}\n", + " count = 0\n", + " \n", + " for c in arr:\n", + " if k-c in my_dict:\n", + " count += 1\n", + " else:\n", + " my_dict.update({c: 1})\n", + " \n", + " return count" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pair_sum([1,3,2,2],4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestPair(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6)\n", + " assert_equal(sol([1,2,3,1],3),1)\n", + " assert_equal(sol([1,3,2,2],4),2)\n", + " print('ALL TEST CASES PASSED')\n", + " \n", + "#Run tests\n", + "t = TestPair()\n", + "t.test(pair_sum)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Find the Missing Element - Tung-checkpoint.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Find the Missing Element - Tung-checkpoint.ipynb new file mode 100644 index 00000000..6cf697a6 --- /dev/null +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/.ipynb_checkpoints/Find the Missing Element - Tung-checkpoint.ipynb @@ -0,0 +1,161 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Find the Missing Element\n", + "\n", + "## Problem\n", + "\n", + "Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given these two arrays, find which element is missing in the second array. \n", + "\n", + "Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array.\n", + "\n", + "Input:\n", + " \n", + " finder([1,2,3,4,5,6,7],[3,7,2,1,4,6])\n", + "\n", + "Output:\n", + "\n", + " 5 is the missing number\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def finder(arr1,arr2):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "arr1 = [1,2,3,4,5,6,7]\n", + "arr2 = [3,7,2,1,4,6]\n", + "finder(arr1,arr2)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "arr1 = [5,5,7,7]\n", + "arr2 = [5,7,7]\n", + "\n", + "finder(arr1,arr2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "_____" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestFinder(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol([5,5,7,7],[5,7,7]),5)\n", + " assert_equal(sol([1,2,3,4,5,6,7],[3,7,2,1,4,6]),5)\n", + " assert_equal(sol([9,8,7,6,5,4,3,2,1],[9,8,7,5,4,3,2,1]),6)\n", + " print 'ALL TEST CASES PASSED'\n", + "\n", + "# Run test\n", + "t = TestFinder()\n", + "t.test(finder)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Anagram Check - Tung Practice.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Anagram Check - Tung Practice.ipynb new file mode 100644 index 00000000..8628340f --- /dev/null +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Anagram Check - Tung Practice.ipynb @@ -0,0 +1,206 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Anagram Check\n", + "\n", + "## Problem\n", + "\n", + "Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). \n", + "\n", + "For example:\n", + "\n", + " \"public relations\" is an anagram of \"crap built on lies.\"\n", + " \n", + " \"clint eastwood\" is an anagram of \"old west action\"\n", + " \n", + "**Note: Ignore spaces and capitalization. So \"d go\" is an anagram of \"God\" and \"dog\" and \"o d g\".**\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "def anagram(s1,s2):\n", + " '''\n", + " Tung practice\n", + " '''\n", + " new_dict = {}\n", + " for c in s1:\n", + " if c in new_dict:\n", + " _val = new_dict[c]\n", + " new_dict.update({c: _val+1})\n", + " else:\n", + " if c != \" \":\n", + " new_dict.update({c: 1})\n", + " for c in s2:\n", + " if c != \" \":\n", + " if not c in new_dict:\n", + " return False\n", + " else:\n", + " _val = new_dict[c]\n", + " new_dict.update({c: _val-1})\n", + " for d in new_dict.values():\n", + " if d != 0:\n", + " return False\n", + " \n", + " return True" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram('dog','god')" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram('clint eastwood','old west action')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram('aa','bb')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "Run the cell below to test your solution" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class AnagramTest(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol('go go go','gggooo'),True)\n", + " assert_equal(sol('abc','cba'),True)\n", + " assert_equal(sol('hi man','hi man'),True)\n", + " assert_equal(sol('aabbcc','aabbc'),False)\n", + " assert_equal(sol('123','1 2'),False)\n", + " print(\"ALL TEST CASES PASSED\")\n", + "\n", + "# Run Tests\n", + "t = AnagramTest()\n", + "t.test(anagram)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "t.test(anagram2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Anagram Check .ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Anagram Check .ipynb index fd6f0824..610f2884 100644 --- a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Anagram Check .ipynb +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Anagram Check .ipynb @@ -26,9 +26,7 @@ { "cell_type": "code", "execution_count": 26, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "def anagram(s1,s2):\n", @@ -39,9 +37,7 @@ { "cell_type": "code", "execution_count": 27, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -61,9 +57,7 @@ { "cell_type": "code", "execution_count": 34, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -83,9 +77,7 @@ { "cell_type": "code", "execution_count": 35, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -113,9 +105,7 @@ { "cell_type": "code", "execution_count": 44, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -149,9 +139,7 @@ { "cell_type": "code", "execution_count": 45, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -175,23 +163,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Array Pair Sum - Tung.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Array Pair Sum - Tung.ipynb new file mode 100644 index 00000000..e90291a4 --- /dev/null +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Array Pair Sum - Tung.ipynb @@ -0,0 +1,138 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Array Pair Sum\n", + "\n", + "## Problem\n", + "\n", + "Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**.\n", + "\n", + "So the input:\n", + " \n", + " pair_sum([1,3,2,2],4)\n", + "\n", + "would return **2** pairs:\n", + "\n", + " (1,3)\n", + " (2,2)\n", + "\n", + "**NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS**\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "def pair_sum(arr,k):\n", + " \n", + " my_dict = {}\n", + " count = 0\n", + " \n", + " for c in arr:\n", + " if k-c in my_dict:\n", + " count += 1\n", + " else:\n", + " my_dict.update({c: 1})\n", + " \n", + " return count" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pair_sum([1,3,2,2],4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestPair(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6)\n", + " assert_equal(sol([1,2,3,1],3),1)\n", + " assert_equal(sol([1,3,2,2],4),2)\n", + " print('ALL TEST CASES PASSED')\n", + " \n", + "#Run tests\n", + "t = TestPair()\n", + "t.test(pair_sum)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Array Pair Sum .ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Array Pair Sum .ipynb index 50ee6bfa..acf223bd 100644 --- a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Array Pair Sum .ipynb +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Array Pair Sum .ipynb @@ -42,9 +42,7 @@ { "cell_type": "code", "execution_count": 14, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -71,9 +69,7 @@ { "cell_type": "code", "execution_count": 16, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -113,23 +109,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Find the Missing Element - Tung.ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Find the Missing Element - Tung.ipynb new file mode 100644 index 00000000..6b526554 --- /dev/null +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Find the Missing Element - Tung.ipynb @@ -0,0 +1,171 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Find the Missing Element\n", + "\n", + "## Problem\n", + "\n", + "Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given these two arrays, find which element is missing in the second array. \n", + "\n", + "Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array.\n", + "\n", + "Input:\n", + " \n", + " finder([1,2,3,4,5,6,7],[3,7,2,1,4,6])\n", + "\n", + "Output:\n", + "\n", + " 5 is the missing number\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def finder(arr1,arr2):\n", + " \n", + " my_dict = {}\n", + " \n", + " for i in arr1:\n", + " if i in my_dict:\n", + " my_dict[i] += 1\n", + " else:\n", + " my_dict[i] = 1\n", + " for i in arr2:\n", + " if i in my_dict:\n", + " my_dict[i] -= 1\n", + " for i in my_dict:\n", + " if my_dict[i] != 0:\n", + " return i" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "arr1 = [1,2,3,4,5,6,7]\n", + "arr2 = [3,7,2,1,4,6]\n", + "finder(arr1,arr2)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "arr1 = [5,5,7,7]\n", + "arr2 = [5,7,7]\n", + "\n", + "finder(arr1,arr2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "_____" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestFinder(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol([5,5,7,7],[5,7,7]),5)\n", + " assert_equal(sol([1,2,3,4,5,6,7],[3,7,2,1,4,6]),5)\n", + " assert_equal(sol([9,8,7,6,5,4,3,2,1],[9,8,7,5,4,3,2,1]),6)\n", + " print('ALL TEST CASES PASSED')\n", + "\n", + "# Run test\n", + "t = TestFinder()\n", + "t.test(finder)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Find the Missing Element .ipynb b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Find the Missing Element .ipynb index fe1e12d7..6cf697a6 100644 --- a/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Find the Missing Element .ipynb +++ b/Array Sequences/Array Sequences Interview Questions/Array Sequence Interview Questions/Find the Missing Element .ipynb @@ -41,9 +41,7 @@ { "cell_type": "code", "execution_count": 46, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -65,9 +63,7 @@ { "cell_type": "code", "execution_count": 47, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -89,9 +85,7 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": false - }, + "metadata": {}, "source": [ "_____" ] @@ -106,9 +100,7 @@ { "cell_type": "code", "execution_count": 43, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -147,23 +139,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Array Sequences/Dynamic Array Exercise.ipynb b/Array Sequences/Dynamic Array Exercise.ipynb index 2b484bd7..0a5db443 100644 --- a/Array Sequences/Dynamic Array Exercise.ipynb +++ b/Array Sequences/Dynamic Array Exercise.ipynb @@ -301,7 +301,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/Array Sequences/Introduction to Array Based Sequences.ipynb b/Array Sequences/Introduction to Array Based Sequences.ipynb index b9225c24..f34032eb 100644 --- a/Array Sequences/Introduction to Array Based Sequences.ipynb +++ b/Array Sequences/Introduction to Array Based Sequences.ipynb @@ -12,9 +12,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -35,9 +33,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -58,9 +54,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -90,23 +84,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems - SOLUTIONS/Linked List Reversal - SOLUTION.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems - SOLUTIONS/Linked List Reversal - SOLUTION.ipynb index 5ac84405..03233d91 100644 --- a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems - SOLUTIONS/Linked List Reversal - SOLUTION.ipynb +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems - SOLUTIONS/Linked List Reversal - SOLUTION.ipynb @@ -115,9 +115,7 @@ { "cell_type": "code", "execution_count": 44, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -138,9 +136,7 @@ { "cell_type": "code", "execution_count": 45, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "ename": "AttributeError", @@ -168,9 +164,7 @@ { "cell_type": "code", "execution_count": 46, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -190,9 +184,7 @@ { "cell_type": "code", "execution_count": 49, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -213,9 +205,7 @@ { "cell_type": "code", "execution_count": 50, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "ename": "AttributeError", @@ -245,23 +235,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Implement a Doubly Linked List-checkpoint.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Implement a Doubly Linked List-checkpoint.ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Implement a Doubly Linked List-checkpoint.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Implement a Doubly Linked List-checkpoint.ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Implement a Singly Linked List-checkpoint.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Implement a Singly Linked List-checkpoint.ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Implement a Singly Linked List-checkpoint.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Implement a Singly Linked List-checkpoint.ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Linked List Nth to Last Node -checkpoint.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Nth to Last Node -checkpoint.ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Linked List Nth to Last Node -checkpoint.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Nth to Last Node -checkpoint.ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Reversal - Tung Practice-checkpoint.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Reversal - Tung Practice-checkpoint.ipynb new file mode 100644 index 00000000..05f8f1c5 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Reversal - Tung Practice-checkpoint.ipynb @@ -0,0 +1,234 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Linked List Reversal \n", + "\n", + "## Problem\n", + "\n", + "Write a function to reverse a Linked List in place. The function will take in the head of the list as input and return the new head of the list.\n", + "\n", + "You are given the example Linked List Node class:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node(object):\n", + " \n", + " def __init__(self,value):\n", + " \n", + " self.value = value\n", + " self.nextnode = None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def reverse(head):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "**Note, this isn't a classic run cell for testing your solution, please read the statements below carefully**\n", + "\n", + "You should be able to easily test your own solution to make sure it works. Given the short list a,b,c,d with values 1,2,3,4. Check the effect of your reverse function and make sure the results match the logic here below:" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create a list of 4 nodes\n", + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "d = Node(4)\n", + "\n", + "# Set up order a,b,c,d with values 1,2,3,4\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = d" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now let's check the values of the nodes coming after a, b and c:" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "print a.nextnode.value\n", + "print b.nextnode.value\n", + "print c.nextnode.value" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'NoneType' object has no attribute 'value'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0md\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnextnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'value'" + ] + } + ], + "source": [ + "d.nextnode.value" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So far so good. Note how there is no value proceeding the last node, this makes sense! Now let's reverse the linked list, we should see the opposite order of values!" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "<__main__.Node at 0x104bd7dd0>" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reverse(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "2\n", + "1\n" + ] + } + ], + "source": [ + "print d.nextnode.value\n", + "print c.nextnode.value\n", + "print b.nextnode.value" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'NoneType' object has no attribute 'value'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mprint\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnextnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m \u001b[0;31m# This will give an error since it now points to None\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'value'" + ] + } + ], + "source": [ + "print a.nextnode.value # This will give an error since it now points to None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Great, now we can see that each of the values points to its previous value (although now that the linked list is reversed we can see the ordering has also reversed)\n", + "\n", + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Linked List Reversal -checkpoint.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Reversal -checkpoint.ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Linked List Reversal -checkpoint.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Reversal -checkpoint.ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Singly Linked List Cycle Check-checkpoint.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Singly Linked List Cycle Check-checkpoint.ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /.ipynb_checkpoints/Singly Linked List Cycle Check-checkpoint.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Singly Linked List Cycle Check-checkpoint.ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Implement a Doubly Linked List.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Implement a Doubly Linked List.ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Implement a Doubly Linked List.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Implement a Doubly Linked List.ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Implement a Singly Linked List.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Implement a Singly Linked List.ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Implement a Singly Linked List.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Implement a Singly Linked List.ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Linked List Nth to Last Node .ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Nth to Last Node .ipynb similarity index 100% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Linked List Nth to Last Node .ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Nth to Last Node .ipynb diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Reversal - Tung Practice.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Reversal - Tung Practice.ipynb new file mode 100644 index 00000000..05f8f1c5 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Reversal - Tung Practice.ipynb @@ -0,0 +1,234 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Linked List Reversal \n", + "\n", + "## Problem\n", + "\n", + "Write a function to reverse a Linked List in place. The function will take in the head of the list as input and return the new head of the list.\n", + "\n", + "You are given the example Linked List Node class:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node(object):\n", + " \n", + " def __init__(self,value):\n", + " \n", + " self.value = value\n", + " self.nextnode = None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def reverse(head):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "**Note, this isn't a classic run cell for testing your solution, please read the statements below carefully**\n", + "\n", + "You should be able to easily test your own solution to make sure it works. Given the short list a,b,c,d with values 1,2,3,4. Check the effect of your reverse function and make sure the results match the logic here below:" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create a list of 4 nodes\n", + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "d = Node(4)\n", + "\n", + "# Set up order a,b,c,d with values 1,2,3,4\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = d" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now let's check the values of the nodes coming after a, b and c:" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "print a.nextnode.value\n", + "print b.nextnode.value\n", + "print c.nextnode.value" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'NoneType' object has no attribute 'value'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0md\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnextnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'value'" + ] + } + ], + "source": [ + "d.nextnode.value" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So far so good. Note how there is no value proceeding the last node, this makes sense! Now let's reverse the linked list, we should see the opposite order of values!" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "<__main__.Node at 0x104bd7dd0>" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reverse(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "2\n", + "1\n" + ] + } + ], + "source": [ + "print d.nextnode.value\n", + "print c.nextnode.value\n", + "print b.nextnode.value" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'NoneType' object has no attribute 'value'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mprint\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnextnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m \u001b[0;31m# This will give an error since it now points to None\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'value'" + ] + } + ], + "source": [ + "print a.nextnode.value # This will give an error since it now points to None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Great, now we can see that each of the values points to its previous value (although now that the linked list is reversed we can see the ordering has also reversed)\n", + "\n", + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Linked List Reversal .ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Reversal .ipynb similarity index 93% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Linked List Reversal .ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Reversal .ipynb index d6d333eb..05f8f1c5 100644 --- a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Linked List Reversal .ipynb +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Reversal .ipynb @@ -92,9 +92,7 @@ { "cell_type": "code", "execution_count": 44, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -115,9 +113,7 @@ { "cell_type": "code", "execution_count": 45, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "ename": "AttributeError", @@ -145,9 +141,7 @@ { "cell_type": "code", "execution_count": 46, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -167,9 +161,7 @@ { "cell_type": "code", "execution_count": 49, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -190,9 +182,7 @@ { "cell_type": "code", "execution_count": 50, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "ename": "AttributeError", @@ -222,23 +212,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Singly Linked List Cycle Check.ipynb b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Singly Linked List Cycle Check.ipynb similarity index 93% rename from Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Singly Linked List Cycle Check.ipynb rename to Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Singly Linked List Cycle Check.ipynb index 8c41dde7..5ae1a6d1 100644 --- a/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems /Singly Linked List Cycle Check.ipynb +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Singly Linked List Cycle Check.ipynb @@ -63,9 +63,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -125,23 +123,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 1 - SOLUTION-checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 1 - SOLUTION-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 1 - SOLUTION-checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 1 - SOLUTION-checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 2 - SOLUTION-checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 2 - SOLUTION-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 2 - SOLUTION-checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 2 - SOLUTION-checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 3 -SOLUTION-checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 3 -SOLUTION-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 3 -SOLUTION-checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 3 -SOLUTION-checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 4 - SOLUTION-checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 4 - SOLUTION-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 4 - SOLUTION-checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 4 - SOLUTION-checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 1 - SOLUTION.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 1 - SOLUTION.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 1 - SOLUTION.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 1 - SOLUTION.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 2 - SOLUTION.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 2 - SOLUTION.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 2 - SOLUTION.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 2 - SOLUTION.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 3 -SOLUTION.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 3 -SOLUTION.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 3 -SOLUTION.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 3 -SOLUTION.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 4 - SOLUTION.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 4 - SOLUTION.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 4 - SOLUTION.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 4 - SOLUTION.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/Phone Screen.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/Phone Screen.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems - SOLUTIONS/Phone Screen.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems - SOLUTIONS/Phone Screen.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 4 -checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 4 -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 4 -checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 4 -checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 1 .ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 1 .ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 1 .ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 1 .ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 2 .ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 2 .ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 2 .ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 2 .ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 3 .ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 3 .ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 3 .ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 3 .ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 4 .ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 4 .ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/On-Site Question 4 .ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/On-Site Question 4 .ipynb diff --git a/Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/Phone Screen.ipynb b/Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/Phone Screen.ipynb similarity index 100% rename from Mock Interviews/Large Search Engine Company /Search Engine Company - Interview Problems/Phone Screen.ipynb rename to Mock Interviews/Large Search Engine Company_/Search Engine Company - Interview Problems/Phone Screen.ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/Phone Screen -checkpoint.ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/Phone Screen -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /.ipynb_checkpoints/Phone Screen -checkpoint.ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/.ipynb_checkpoints/Phone Screen -checkpoint.ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /On-Site Question 1 .ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/On-Site Question 1 .ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /On-Site Question 1 .ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/On-Site Question 1 .ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /On-Site Question 2 .ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/On-Site Question 2 .ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /On-Site Question 2 .ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/On-Site Question 2 .ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /On-Site Question 3 .ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/On-Site Question 3 .ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /On-Site Question 3 .ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/On-Site Question 3 .ipynb diff --git a/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /Phone Screen .ipynb b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/Phone Screen .ipynb similarity index 100% rename from Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions /Phone Screen .ipynb rename to Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions_/Phone Screen .ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/On-Site Question 1-checkpoint.ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 1-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/On-Site Question 1-checkpoint.ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 1-checkpoint.ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/On-Site Question 2-checkpoint.ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 2-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/On-Site Question 2-checkpoint.ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 2-checkpoint.ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/On-Site Question 3-checkpoint.ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 3-checkpoint.ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/On-Site Question 3-checkpoint.ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/On-Site Question 3-checkpoint.ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/Phone Screen -checkpoint.ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/Phone Screen -checkpoint.ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /.ipynb_checkpoints/Phone Screen -checkpoint.ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/.ipynb_checkpoints/Phone Screen -checkpoint.ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /On-Site Question 1.ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/On-Site Question 1.ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /On-Site Question 1.ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/On-Site Question 1.ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /On-Site Question 2.ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/On-Site Question 2.ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /On-Site Question 2.ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/On-Site Question 2.ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /On-Site Question 3.ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/On-Site Question 3.ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /On-Site Question 3.ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/On-Site Question 3.ipynb diff --git a/Mock Interviews/Social Network Company/Social Network Company - Interview Questions /Phone Screen .ipynb b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/Phone Screen .ipynb similarity index 100% rename from Mock Interviews/Social Network Company/Social Network Company - Interview Questions /Phone Screen .ipynb rename to Mock Interviews/Social Network Company/Social Network Company - Interview Questions_/Phone Screen .ipynb diff --git a/Recursion/Introduction to Recursion.ipynb b/Recursion/Introduction to Recursion.ipynb index 0a165bd9..47d4ec65 100644 --- a/Recursion/Introduction to Recursion.ipynb +++ b/Recursion/Introduction to Recursion.ipynb @@ -58,9 +58,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "def fact(n):\n", @@ -87,9 +85,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -118,9 +114,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -158,23 +152,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Recursion/Recursion Homework Example Problems.ipynb b/Recursion/Recursion Homework Example Problems.ipynb index ebe52213..09fbd5a2 100644 --- a/Recursion/Recursion Homework Example Problems.ipynb +++ b/Recursion/Recursion Homework Example Problems.ipynb @@ -40,9 +40,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -85,9 +83,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -114,9 +110,7 @@ { "cell_type": "code", "execution_count": 13, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -137,9 +131,7 @@ { "cell_type": "code", "execution_count": 14, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -182,9 +174,7 @@ { "cell_type": "code", "execution_count": 32, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -204,9 +194,7 @@ { "cell_type": "code", "execution_count": 33, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -226,9 +214,7 @@ { "cell_type": "code", "execution_count": 34, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -248,9 +234,7 @@ { "cell_type": "code", "execution_count": 24, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "def word_split(phrase,list_of_words, output = None):\n", @@ -269,23 +253,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 2 - String Permutation- SOLUTION.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 2 - String Permutation- SOLUTION.ipynb index a45943a5..f869d8eb 100644 --- a/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 2 - String Permutation- SOLUTION.ipynb +++ b/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 2 - String Permutation- SOLUTION.ipynb @@ -163,7 +163,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 4 - Coin Change - SOLUTION.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 4 - Coin Change - SOLUTION.ipynb index 2368b86b..a69f69e8 100644 --- a/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 4 - Coin Change - SOLUTION.ipynb +++ b/Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 4 - Coin Change - SOLUTION.ipynb @@ -291,7 +291,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 1 - Reverse String - Tung-checkpoint.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 1 - Reverse String - Tung-checkpoint.ipynb new file mode 100644 index 00000000..cd040c29 --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 1 - Reverse String - Tung-checkpoint.ipynb @@ -0,0 +1,151 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Reverse a String\n", + "\n", + "This interview question requires you to reverse a string using recursion. Make sure to think of the base case here.\n", + "\n", + "Again, make sure you use *recursion* to accomplish this. **Do not slice (e.g. string[::-1]) or use iteration, there must be a recursive call for the function.**\n", + "\n", + "____\n", + "\n", + "### Fill out your solution below" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "def reverse(s):\n", + " \n", + " if len(s) == 1:\n", + " return s\n", + " else:\n", + " return ''.join([reverse(s[1:]),s[0]])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'dlrow olleh'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reverse('hello world')" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'dlrow olleh'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reverse('hello world')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Test Your Solution\n", + "\n", + "Run the cell below to test your solution against the following cases:\n", + "\n", + " string = 'hello'\n", + " string = 'hello world'\n", + " string = '123456789'" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PASSED ALL TEST CASES!\n" + ] + } + ], + "source": [ + "'''\n", + "RUN THIS CELL TO TEST YOUR FUNCTION AGAINST SOME TEST CASES\n", + "'''\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestReverse(object):\n", + " \n", + " def test_rev(self,solution):\n", + " assert_equal(solution('hello'),'olleh')\n", + " assert_equal(solution('hello world'),'dlrow olleh')\n", + " assert_equal(solution('123456789'),'987654321')\n", + " \n", + " print('PASSED ALL TEST CASES!')\n", + " \n", + "# Run Tests\n", + "test = TestReverse()\n", + "test.test_rev(reverse)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Good Luck!**" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 2 - String Permutation - Tung-checkpoint.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 2 - String Permutation - Tung-checkpoint.ipynb new file mode 100644 index 00000000..63af6604 --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 2 - String Permutation - Tung-checkpoint.ipynb @@ -0,0 +1,131 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# String Permutation\n", + "\n", + "## Problem Statement\n", + "\n", + "Given a string, write a function that uses recursion to output a list of all the possible permutations of that string.\n", + "\n", + "For example, given s='abc' the function should return ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']\n", + "\n", + "*Note: If a character is repeated, treat each occurence as distinct, for example an input of 'xxx' would return a list with 6 \"versions\" of 'xxx'*\n", + "\n", + "\n", + "## Fill Out Your Solution Below\n", + "\n", + "Let's think about what the steps we need to take here are:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def permute(s):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['abc', 'acb', 'bac', 'bca', 'cab', 'cba']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "permute('abc')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____\n", + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "All test cases passed.\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION.\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestPerm(object):\n", + " \n", + " def test(self,solution):\n", + " \n", + " assert_equal(sorted(solution('abc')),sorted(['abc', 'acb', 'bac', 'bca', 'cab', 'cba']))\n", + " assert_equal(sorted(solution('dog')),sorted(['dog', 'dgo', 'odg', 'ogd', 'gdo', 'god']) )\n", + " \n", + " print 'All test cases passed.'\n", + " \n", + "\n", + "\n", + "# Run Tests\n", + "t = TestPerm()\n", + "t.test(permute)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Luck!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 3 - Fibonacci Sequence - Tung-checkpoint.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 3 - Fibonacci Sequence - Tung-checkpoint.ipynb new file mode 100644 index 00000000..3f03e39e --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 3 - Fibonacci Sequence - Tung-checkpoint.ipynb @@ -0,0 +1,236 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Fibonnaci Sequence\n", + "\n", + "In this interview excercise we will begin to get a feel of having to solve a single problem multiple ways!\n", + "\n", + "## Problem Statement\n", + "\n", + "Implement a [Fibonnaci Sequence](https://en.wikipedia.org/wiki/Fibonacci_number) in three different ways:\n", + "\n", + "* Recursively\n", + "* Dynamically (Using Memoization to store results)\n", + "* Iteratively\n", + "___\n", + "#### Function Output\n", + "Your function will accept a number **n** and return the **nth** number of the fibonacci sequence\n", + "___\n", + "Remember that a fibonacci sequence: 0,1,1,2,3,5,8,13,21,... starts off with a base case checking to see if n = 0 or 1, then it returns 1. \n", + "\n", + "Else it returns fib(n-1)+fib(n+2).\n", + "\n", + "____\n", + "\n", + "## Fill Out Your Solutions Below" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Recursively\n", + "\n", + "Solve the problem using simple recursion." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def fib_rec(n):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "55" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fib_rec(10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Dynamically\n", + "\n", + "Implement the function using dynamic programming by using a cache to store results (memoization)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# Instantiate Cache information\n", + "n = 10\n", + "cache = [None] * (n + 1)\n", + "\n", + "\n", + "def fib_dyn(n):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "55" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fib_dyn(10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Iteratively\n", + "\n", + "Implement the solution with simple iteration." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def fib_iter(n):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "28657" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fib_iter(23)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "Run the cell below to test your solutions, simply uncomment the solution functions you wish to test!" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Passed all tests.\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "UNCOMMENT THE CODE AT THE BOTTOM OF THIS CELL TO SELECT WHICH SOLUTIONS TO TEST.\n", + "THEN RUN THE CELL.\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestFib(object):\n", + " \n", + " def test(self,solution):\n", + " assert_equal(solution(10),55)\n", + " assert_equal(solution(1),1)\n", + " assert_equal(solution(23),28657)\n", + " print 'Passed all tests.'\n", + "# UNCOMMENT FOR CORRESPONDING FUNCTION\n", + "t = TestFib()\n", + "\n", + "t.test(fib_rec)\n", + "#t.test(fib_dyn) # Note, will need to reset cache size for each test!\n", + "#t.test(fib_iter)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Conclusion\n", + "\n", + "Hopefully this interview question served as a good excercise in exploring recursion, dynamic programming, and iterative solutions for a single problem! Its good to work through all three because in an interview a common question may just begin with requesting a recursive solution and then checking to se if you can implement the other forms!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 4 - Coin Change - Tung-checkpoint.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 4 - Coin Change - Tung-checkpoint.ipynb new file mode 100644 index 00000000..424eb836 --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/.ipynb_checkpoints/Recursion Problem 4 - Coin Change - Tung-checkpoint.ipynb @@ -0,0 +1,143 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Coin Change Problem\n", + "\n", + "##### Note: This problem has multiple solutions and is a classic problem in showing issues with basic recursion. If you are having trouble with this problem (or it seems to be taking a long time to run in some cases) check out the Solution Notebook and fully read the conclusion link for a detailed description of the various ways to solve this problem!\n", + "\n", + "\n", + "This problem is common enough that is actually has its own [Wikipedia Entry](https://en.wikipedia.org/wiki/Change-making_problem)! \n", + "\n", + "____\n", + "## Problem Statement\n", + "Given a target amount **n** and a list (array) of distinct coin values, what's the fewest coins needed to make the change amount. \n", + "\n", + "For example:\n", + "\n", + "If n = 10 and coins = [1,5,10]. Then there are 4 possible ways to make change:\n", + "\n", + "* 1+1+1+1+1+1+1+1+1+1\n", + "\n", + "* 5 + 1+1+1+1+1\n", + "\n", + "* 5+5\n", + "\n", + "* 10\n", + "\n", + "With 1 coin being the minimum amount.\n", + "\n", + " \n", + "## Solution\n", + "\n", + "Implement your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def rec_coin(target,coins):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rec_coin(10,[1,5])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "Run the cell below to test your function against some test cases. \n", + "\n", + "**Note that the TestCoins class only test functions with two parameter inputs, the list of coins and the target**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR FUNCTION.\n", + "NOTE: NON-DYNAMIC FUNCTIONS WILL TAKE A LONG TIME TO TEST. IF YOU BELIEVE YOU HAVE A SOLUTION \n", + " GO CHECK THE SOLUTION NOTEBOOK INSTEAD OF RUNNING THIS!\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestCoins(object):\n", + " \n", + " def check(self,solution):\n", + " coins = [1,5,10,25]\n", + " assert_equal(solution(45,coins),3)\n", + " assert_equal(solution(23,coins),5)\n", + " assert_equal(solution(74,coins),8)\n", + " print 'Passed all tests.'\n", + "# Run Test\n", + "\n", + "test = TestCoins()\n", + "test.check(rec_coin)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## EXTRA\n", + "\n", + "Good luck and remember to read the solution notebook for this once you've think you have a solution!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 1 - Reverse String - Tung.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 1 - Reverse String - Tung.ipynb new file mode 100644 index 00000000..cd040c29 --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 1 - Reverse String - Tung.ipynb @@ -0,0 +1,151 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Reverse a String\n", + "\n", + "This interview question requires you to reverse a string using recursion. Make sure to think of the base case here.\n", + "\n", + "Again, make sure you use *recursion* to accomplish this. **Do not slice (e.g. string[::-1]) or use iteration, there must be a recursive call for the function.**\n", + "\n", + "____\n", + "\n", + "### Fill out your solution below" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "def reverse(s):\n", + " \n", + " if len(s) == 1:\n", + " return s\n", + " else:\n", + " return ''.join([reverse(s[1:]),s[0]])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'dlrow olleh'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reverse('hello world')" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'dlrow olleh'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reverse('hello world')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Test Your Solution\n", + "\n", + "Run the cell below to test your solution against the following cases:\n", + "\n", + " string = 'hello'\n", + " string = 'hello world'\n", + " string = '123456789'" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PASSED ALL TEST CASES!\n" + ] + } + ], + "source": [ + "'''\n", + "RUN THIS CELL TO TEST YOUR FUNCTION AGAINST SOME TEST CASES\n", + "'''\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestReverse(object):\n", + " \n", + " def test_rev(self,solution):\n", + " assert_equal(solution('hello'),'olleh')\n", + " assert_equal(solution('hello world'),'dlrow olleh')\n", + " assert_equal(solution('123456789'),'987654321')\n", + " \n", + " print('PASSED ALL TEST CASES!')\n", + " \n", + "# Run Tests\n", + "test = TestReverse()\n", + "test.test_rev(reverse)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Good Luck!**" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 1 - Reverse String .ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 1 - Reverse String .ipynb index 4d4308f6..ebeec88d 100644 --- a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 1 - Reverse String .ipynb +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 1 - Reverse String .ipynb @@ -18,9 +18,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "def reverse(s):\n", @@ -31,9 +29,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -68,9 +64,7 @@ { "cell_type": "code", "execution_count": 13, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -111,23 +105,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 2 - String Permutation - Tung.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 2 - String Permutation - Tung.ipynb new file mode 100644 index 00000000..63af6604 --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 2 - String Permutation - Tung.ipynb @@ -0,0 +1,131 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# String Permutation\n", + "\n", + "## Problem Statement\n", + "\n", + "Given a string, write a function that uses recursion to output a list of all the possible permutations of that string.\n", + "\n", + "For example, given s='abc' the function should return ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']\n", + "\n", + "*Note: If a character is repeated, treat each occurence as distinct, for example an input of 'xxx' would return a list with 6 \"versions\" of 'xxx'*\n", + "\n", + "\n", + "## Fill Out Your Solution Below\n", + "\n", + "Let's think about what the steps we need to take here are:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def permute(s):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['abc', 'acb', 'bac', 'bca', 'cab', 'cba']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "permute('abc')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____\n", + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "All test cases passed.\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION.\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestPerm(object):\n", + " \n", + " def test(self,solution):\n", + " \n", + " assert_equal(sorted(solution('abc')),sorted(['abc', 'acb', 'bac', 'bca', 'cab', 'cba']))\n", + " assert_equal(sorted(solution('dog')),sorted(['dog', 'dgo', 'odg', 'ogd', 'gdo', 'god']) )\n", + " \n", + " print 'All test cases passed.'\n", + " \n", + "\n", + "\n", + "# Run Tests\n", + "t = TestPerm()\n", + "t.test(permute)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Luck!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 2 - String Permutation.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 2 - String Permutation.ipynb index e2585c12..63af6604 100644 --- a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 2 - String Permutation.ipynb +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 2 - String Permutation.ipynb @@ -38,9 +38,7 @@ { "cell_type": "code", "execution_count": 24, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -68,9 +66,7 @@ { "cell_type": "code", "execution_count": 25, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -113,23 +109,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 3 - Fibonacci Sequence - Tung.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 3 - Fibonacci Sequence - Tung.ipynb new file mode 100644 index 00000000..c62c8b8b --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 3 - Fibonacci Sequence - Tung.ipynb @@ -0,0 +1,250 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Fibonnaci Sequence\n", + "\n", + "In this interview excercise we will begin to get a feel of having to solve a single problem multiple ways!\n", + "\n", + "## Problem Statement\n", + "\n", + "Implement a [Fibonnaci Sequence](https://en.wikipedia.org/wiki/Fibonacci_number) in three different ways:\n", + "\n", + "* Recursively\n", + "* Dynamically (Using Memoization to store results)\n", + "* Iteratively\n", + "___\n", + "#### Function Output\n", + "Your function will accept a number **n** and return the **nth** number of the fibonacci sequence\n", + "___\n", + "Remember that a fibonacci sequence: 0,1,1,2,3,5,8,13,21,... starts off with a base case checking to see if n = 0 or 1, then it returns 1. \n", + "\n", + "Else it returns fib(n-1)+fib(n+2).\n", + "\n", + "____\n", + "\n", + "## Fill Out Your Solutions Below" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Recursively\n", + "\n", + "Solve the problem using simple recursion." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def fib_rec(n):\n", + " if n == 0:\n", + " return 0\n", + " if n == 1:\n", + " return 1\n", + " \n", + " return fib_rec(n-1) + fib_rec(n-2)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "55" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fib_rec(10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Dynamically\n", + "\n", + "Implement the function using dynamic programming by using a cache to store results (memoization)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# Instantiate Cache information\n", + "\n", + "def fib_dyn(n):\n", + " cache = [None] * (n + 1)\n", + " \n", + " return fib_dyn_helper(n, cache)\n", + " \n", + "\n", + "def fib_dyn_helper(n, cache):\n", + " \n", + " \n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "55" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fib_dyn(10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Iteratively\n", + "\n", + "Implement the solution with simple iteration." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "def fib_iter(n):\n", + " first = 0\n", + " second = 1\n", + " \n", + " for i in range(n-1):\n", + " second = second + first\n", + " first = second - first\n", + " \n", + " return second" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "28657" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fib_iter(23)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "Run the cell below to test your solutions, simply uncomment the solution functions you wish to test!" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Passed all tests.\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "UNCOMMENT THE CODE AT THE BOTTOM OF THIS CELL TO SELECT WHICH SOLUTIONS TO TEST.\n", + "THEN RUN THE CELL.\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestFib(object):\n", + " \n", + " def test(self,solution):\n", + " assert_equal(solution(10),55)\n", + " assert_equal(solution(1),1)\n", + " assert_equal(solution(23),28657)\n", + " print('Passed all tests.')\n", + "# UNCOMMENT FOR CORRESPONDING FUNCTION\n", + "t = TestFib()\n", + "\n", + "#t.test(fib_rec)\n", + "#t.test(fib_dyn) # Note, will need to reset cache size for each test!\n", + "#t.test(fib_iter)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Conclusion\n", + "\n", + "Hopefully this interview question served as a good excercise in exploring recursion, dynamic programming, and iterative solutions for a single problem! Its good to work through all three because in an interview a common question may just begin with requesting a recursive solution and then checking to se if you can implement the other forms!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 3 - Fibonacci Sequence.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 3 - Fibonacci Sequence.ipynb index e85c24d0..3f03e39e 100644 --- a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 3 - Fibonacci Sequence.ipynb +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 3 - Fibonacci Sequence.ipynb @@ -42,9 +42,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "def fib_rec(n):\n", @@ -55,9 +53,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -86,9 +82,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Instantiate Cache information\n", @@ -104,9 +98,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -148,9 +140,7 @@ { "cell_type": "code", "execution_count": 14, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -179,9 +169,7 @@ { "cell_type": "code", "execution_count": 19, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -226,23 +214,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 4 - Coin Change - Tung.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 4 - Coin Change - Tung.ipynb new file mode 100644 index 00000000..e28b03b1 --- /dev/null +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 4 - Coin Change - Tung.ipynb @@ -0,0 +1,150 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Coin Change Problem\n", + "\n", + "##### Note: This problem has multiple solutions and is a classic problem in showing issues with basic recursion. If you are having trouble with this problem (or it seems to be taking a long time to run in some cases) check out the Solution Notebook and fully read the conclusion link for a detailed description of the various ways to solve this problem!\n", + "\n", + "\n", + "This problem is common enough that is actually has its own [Wikipedia Entry](https://en.wikipedia.org/wiki/Change-making_problem)! \n", + "\n", + "____\n", + "## Problem Statement\n", + "Given a target amount **n** and a list (array) of distinct coin values, what's the fewest coins needed to make the change amount. \n", + "\n", + "For example:\n", + "\n", + "If n = 10 and coins = [1,5,10]. Then there are 4 possible ways to make change:\n", + "\n", + "* 1+1+1+1+1+1+1+1+1+1\n", + "\n", + "* 5 + 1+1+1+1+1\n", + "\n", + "* 5+5\n", + "\n", + "* 10\n", + "\n", + "With 1 coin being the minimum amount.\n", + "\n", + " \n", + "## Solution\n", + "\n", + "Implement your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def rec_coin(target,coins):\n", + " \n", + " cache = [target] * (target + 1)\n", + " \n", + " cache[0] = 0\n", + " \n", + " for i in range(target):\n", + " for j in coins:\n", + " if (i - j >= 0):\n", + " cache[i] = min(target, cache[i-j] + 1)\n", + " \n", + " return cache[target]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rec_coin(10,[1,5])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "Run the cell below to test your function against some test cases. \n", + "\n", + "**Note that the TestCoins class only test functions with two parameter inputs, the list of coins and the target**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR FUNCTION.\n", + "NOTE: NON-DYNAMIC FUNCTIONS WILL TAKE A LONG TIME TO TEST. IF YOU BELIEVE YOU HAVE A SOLUTION \n", + " GO CHECK THE SOLUTION NOTEBOOK INSTEAD OF RUNNING THIS!\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestCoins(object):\n", + " \n", + " def check(self,solution):\n", + " coins = [1,5,10,25]\n", + " assert_equal(solution(45,coins),3)\n", + " assert_equal(solution(23,coins),5)\n", + " assert_equal(solution(74,coins),8)\n", + " print 'Passed all tests.'\n", + "# Run Test\n", + "\n", + "test = TestCoins()\n", + "test.check(rec_coin)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## EXTRA\n", + "\n", + "Good luck and remember to read the solution notebook for this once you've think you have a solution!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 4 - Coin Change.ipynb b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 4 - Coin Change.ipynb index f8785dfb..424eb836 100644 --- a/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 4 - Coin Change.ipynb +++ b/Recursion/Recursion Interview Problems/Recursion Problems/Recursion Problem 4 - Coin Change.ipynb @@ -53,9 +53,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -86,9 +84,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "\"\"\"\n", @@ -125,23 +121,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Bridge Crossing-checkpoint.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Bridge Crossing-checkpoint.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Bridge Crossing-checkpoint.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Bridge Crossing-checkpoint.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Coins and a Scale -checkpoint.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Coins and a Scale -checkpoint.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Coins and a Scale -checkpoint.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Coins and a Scale -checkpoint.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Egg Drop -checkpoint.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Egg Drop -checkpoint.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Egg Drop -checkpoint.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Egg Drop -checkpoint.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Hallway Lockers-checkpoint.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Hallway Lockers-checkpoint.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Hallway Lockers-checkpoint.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Hallway Lockers-checkpoint.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Jugs of Water -checkpoint.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Jugs of Water -checkpoint.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Jugs of Water -checkpoint.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Jugs of Water -checkpoint.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Light Switches -checkpoint.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Light Switches -checkpoint.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Light Switches -checkpoint.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Light Switches -checkpoint.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Ropes Burning-checkpoint.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Ropes Burning-checkpoint.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /.ipynb_checkpoints/Ropes Burning-checkpoint.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/.ipynb_checkpoints/Ropes Burning-checkpoint.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /Bridge Crossing.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/Bridge Crossing.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /Bridge Crossing.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/Bridge Crossing.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /Coins and a Scale .ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/Coins and a Scale .ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /Coins and a Scale .ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/Coins and a Scale .ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /Egg Drop .ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/Egg Drop .ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /Egg Drop .ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/Egg Drop .ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /Hallway Lockers.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/Hallway Lockers.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /Hallway Lockers.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/Hallway Lockers.ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /Jugs of Water .ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/Jugs of Water .ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /Jugs of Water .ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/Jugs of Water .ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /Light Switches .ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/Light Switches .ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /Light Switches .ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/Light Switches .ipynb diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems /Ropes Burning.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems_/Ropes Burning.ipynb similarity index 100% rename from Riddles/Riddle Interview Problems/Riddle Interview Problems /Ropes Burning.ipynb rename to Riddles/Riddle Interview Problems/Riddle Interview Problems_/Ropes Burning.ipynb diff --git a/Stacks, Queues and Deques/Stacks Overview.ipynb b/Stacks, Queues and Deques/Stacks Overview.ipynb index 8089314d..3171aa49 100644 --- a/Stacks, Queues and Deques/Stacks Overview.ipynb +++ b/Stacks, Queues and Deques/Stacks Overview.ipynb @@ -27,9 +27,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -72,23 +70,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions - PRACTICE/.ipynb_checkpoints/Implement a Queue -Using Two Stacks -checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions - PRACTICE/.ipynb_checkpoints/Implement a Queue -Using Two Stacks -checkpoint.ipynb deleted file mode 100644 index 521c8245..00000000 --- a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions - PRACTICE/.ipynb_checkpoints/Implement a Queue -Using Two Stacks -checkpoint.ipynb +++ /dev/null @@ -1,131 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Implement a Queue - Using Two Stacks\n", - "\n", - "Given the Stack class below, implement a Queue class using **two** stacks! Note, this is a \"classic\" interview problem. Use a Python list data structure as your Stack." - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# Uses lists instead of your own Stack class.\n", - "stack1 = []\n", - "stack2 = []" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Solution\n", - "\n", - "Fill out your solution below:" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [], - "source": [ - "class Queue2Stacks(object):\n", - " \n", - " def __init__(self):\n", - " \n", - " # Two Stacks\n", - " self.in_stack = []\n", - " self.out_stack = []\n", - " \n", - " def enqueue(self, element):\n", - " # FILL OUT CODE HERE\n", - " self.in_stack.append(element)\n", - " pass\n", - " \n", - " def dequeue(self):\n", - " \n", - " # FILL OUT CODE HERE\n", - " if not self.out_stack:\n", - " while self.in_stack:\n", - " self.out_stack.append(self.in_stack.pop())\n", - " return self.out_stack.pop()\n", - " pass" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test Your Solution\n", - "\n", - "You should be able to tell with your current knowledge of Stacks and Queues if this is working as it should. For example, the following should print as such:" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n", - "1\n", - "2\n", - "3\n", - "4\n" - ] - } - ], - "source": [ - "\"\"\"\n", - "RUN THIS CELL TO CHECK THAT YOUR SOLUTION OUTPUT MAKES SENSE AND BEHAVES AS A QUEUE\n", - "\"\"\"\n", - "q = Queue2Stacks()\n", - "\n", - "for i in range(5):\n", - " q.enqueue(i)\n", - " \n", - "for i in range(5):\n", - " print (q.dequeue())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Good Job!" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.2" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/.ipynb_checkpoints/Implement a Queue -Using Two Stacks - SOLUTION-checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/.ipynb_checkpoints/Implement a Queue -Using Two Stacks - SOLUTION-checkpoint.ipynb deleted file mode 100644 index e66de679..00000000 --- a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/.ipynb_checkpoints/Implement a Queue -Using Two Stacks - SOLUTION-checkpoint.ipynb +++ /dev/null @@ -1,134 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Implement a Queue - Using Two Stacks - SOLUTION\n", - "\n", - "Given the Stack class below, implement a Queue class using **two** stacks! Note, this is a \"classic\" interview problem. Use a Python list data structure as your Stack." - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "stack1 = []\n", - "stack2 = []" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Solution\n", - "\n", - "The key insight is that a stack reverses order (while a queue doesn't). A sequence of elements pushed on a stack comes back in reversed order when popped. Consequently, two stacks chained together will return elements in the same order, since reversed order reversed again is original order.\n", - "\n", - " We use an in-stack that we fill when an element is enqueued and the dequeue operation takes elements from an out-stack. If the out-stack is empty we pop all elements from the in-stack and push them onto the out-stack. " - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "class Queue2Stacks(object):\n", - " \n", - " def __init__(self):\n", - " \n", - " # Two Stacks\n", - " self.instack = []\n", - " self.outstack = []\n", - " \n", - " def enqueue(self,element):\n", - " \n", - " # Add an enqueue with the \"IN\" stack\n", - " self.instack.append(element)\n", - " \n", - " def dequeue(self):\n", - " if not self.outstack:\n", - " while self.instack:\n", - " # Add the elements to the outstack to reverse the order when called\n", - " self.outstack.append(self.instack.pop())\n", - " return self.outstack.pop() " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test Your Solution\n", - "\n", - "You should be able to tell with your current knowledge of Stacks and Queues if this is working as it should. For example, the following should print as such:" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n", - "1\n", - "2\n", - "3\n", - "4\n" - ] - } - ], - "source": [ - "\"\"\"\n", - "RUN THIS CELL TO CHECK THAT YOUR SOLUTION OUTPUT MAKES SENSE AND BEHAVES AS A QUEUE\n", - "\"\"\"\n", - "q = Queue2Stacks()\n", - "\n", - "for i in xrange(5):\n", - " q.enqueue(i)\n", - " \n", - "for i in xrange(5):\n", - " print q.dequeue()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Good Job!" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Balanced Parentheses Check - SOLUTION.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Balanced Parentheses Check - SOLUTION.ipynb index 2c988d8f..077527d3 100644 --- a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Balanced Parentheses Check - SOLUTION.ipynb +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Balanced Parentheses Check - SOLUTION.ipynb @@ -196,7 +196,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Implement a Queue -Using Two Stacks - SOLUTION.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Implement a Queue -2 Stacks - SOLUTION.ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Implement a Queue -Using Two Stacks - SOLUTION.ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions -SOLUTIONS/Implement a Queue -2 Stacks - SOLUTION.ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Queue -Using Two Stacks -checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Queue -Using Two Stacks -checkpoint.ipynb deleted file mode 100644 index 907956a6..00000000 --- a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Queue -Using Two Stacks -checkpoint.ipynb +++ /dev/null @@ -1,131 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Implement a Queue - Using Two Stacks\n", - "\n", - "Given the Stack class below, implement a Queue class using **two** stacks! Note, this is a \"classic\" interview problem. Use a Python list data structure as your Stack." - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# Uses lists instead of your own Stack class.\n", - "stack1 = []\n", - "stack2 = []" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Solution\n", - "\n", - "Fill out your solution below:" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "class Queue2Stacks(object):\n", - " \n", - " def __init__(self):\n", - " \n", - " # Two Stacks\n", - " self.stack1 = []\n", - " self.stack2 = []\n", - " \n", - " def enqueue(self,element):\n", - " \n", - " # FILL OUT CODE HERE\n", - " pass\n", - " \n", - " def dequeue(self):\n", - " \n", - " # FILL OUT CODE HERE\n", - " pass " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test Your Solution\n", - "\n", - "You should be able to tell with your current knowledge of Stacks and Queues if this is working as it should. For example, the following should print as such:" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n", - "1\n", - "2\n", - "3\n", - "4\n" - ] - } - ], - "source": [ - "\"\"\"\n", - "RUN THIS CELL TO CHECK THAT YOUR SOLUTION OUTPUT MAKES SENSE AND BEHAVES AS A QUEUE\n", - "\"\"\"\n", - "q = Queue2Stacks()\n", - "\n", - "for i in xrange(5):\n", - " q.enqueue(i)\n", - " \n", - "for i in xrange(5):\n", - " print q.dequeue()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Good Job!" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Balanced Parentheses Check - Tung-checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Balanced Parentheses Check - Tung-checkpoint.ipynb new file mode 100644 index 00000000..235dd993 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Balanced Parentheses Check - Tung-checkpoint.ipynb @@ -0,0 +1,163 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Balanced Parentheses Check \n", + "\n", + "## Problem Statement\n", + "\n", + "Given a string of opening and closing parentheses, check whether it’s balanced. We have 3 types of parentheses: round brackets: (), square brackets: [], and curly brackets: {}. Assume that the string doesn’t contain any other character than these, no spaces words or numbers. As a reminder, balanced parentheses require every opening parenthesis to be closed in the reverse order opened. For example ‘([])’ is balanced but ‘([)]’ is not. \n", + "\n", + "\n", + "You can assume the input string has no spaces.\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def balance_check(s):\n", + " \n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[]')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[](){([[[]]])}')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('()(){]}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestBalanceCheck(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol('[](){([[[]]])}('),False)\n", + " assert_equal(sol('[{{{(())}}}]((()))'),True)\n", + " assert_equal(sol('[[[]])]'),False)\n", + " print 'ALL TEST CASES PASSED'\n", + " \n", + "# Run Tests\n", + "\n", + "t = TestBalanceCheck()\n", + "t.test(balance_check)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Balanced Parentheses Check -checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Balanced Parentheses Check -checkpoint.ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Balanced Parentheses Check -checkpoint.ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Balanced Parentheses Check -checkpoint.ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Deque -checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Deque -checkpoint.ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Deque -checkpoint.ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Deque -checkpoint.ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Queue-checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Queue-checkpoint.ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Queue-checkpoint.ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Queue-checkpoint.ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Stack -checkpoint.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Stack -checkpoint.ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /.ipynb_checkpoints/Implement a Stack -checkpoint.ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Stack -checkpoint.ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check - Tung.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check - Tung.ipynb new file mode 100644 index 00000000..f261f6bc --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check - Tung.ipynb @@ -0,0 +1,179 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Balanced Parentheses Check \n", + "\n", + "## Problem Statement\n", + "\n", + "Given a string of opening and closing parentheses, check whether it’s balanced. We have 3 types of parentheses: round brackets: (), square brackets: [], and curly brackets: {}. Assume that the string doesn’t contain any other character than these, no spaces words or numbers. As a reminder, balanced parentheses require every opening parenthesis to be closed in the reverse order opened. For example ‘([])’ is balanced but ‘([)]’ is not. \n", + "\n", + "\n", + "You can assume the input string has no spaces.\n", + "\n", + "## Solution\n", + "\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "def balance_check(s):\n", + " \n", + " left_parentheses = ('[', '{', '(')\n", + " right_parentheses = (']', '}', ')')\n", + " \n", + " stack = []\n", + " \n", + " for c in s:\n", + " if c in right_parentheses:\n", + " ind = right_parentheses.index(c)\n", + " if stack[-1] != left_parentheses[ind]:\n", + " return False\n", + " else:\n", + " stack.pop()\n", + " else:\n", + " stack.append(c)\n", + " \n", + " if len(stack) != 0:\n", + " return False\n", + "\n", + " return True" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[]')" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[](){([[[]]])}')" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('()(){]}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION\n", + "\"\"\"\n", + "from nose.tools import assert_equal\n", + "\n", + "class TestBalanceCheck(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol('[](){([[[]]])}('),False)\n", + " assert_equal(sol('[{{{(())}}}]((()))'),True)\n", + " assert_equal(sol('[[[]])]'),False)\n", + " print('ALL TEST CASES PASSED')\n", + " \n", + "# Run Tests\n", + "\n", + "t = TestBalanceCheck()\n", + "t.test(balance_check)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good Job!" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Balanced Parentheses Check .ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check .ipynb similarity index 90% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Balanced Parentheses Check .ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check .ipynb index 274f3ace..235dd993 100644 --- a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Balanced Parentheses Check .ipynb +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check .ipynb @@ -34,9 +34,7 @@ { "cell_type": "code", "execution_count": 13, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -56,9 +54,7 @@ { "cell_type": "code", "execution_count": 16, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -78,9 +74,7 @@ { "cell_type": "code", "execution_count": 17, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -107,9 +101,7 @@ { "cell_type": "code", "execution_count": 18, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -149,23 +141,23 @@ ], "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.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Deque .ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Deque .ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Deque .ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Deque .ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Queue -Using Two Stacks .ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Queue -Using Two Stacks .ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Queue -Using Two Stacks .ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Queue -Using Two Stacks .ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Queue.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Queue.ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Queue.ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Queue.ipynb diff --git a/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Stack .ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Stack .ipynb similarity index 100% rename from Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions /Implement a Stack .ipynb rename to Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Stack .ipynb diff --git a/Trees/Binary Search Trees.ipynb b/Trees/Binary Search Trees.ipynb index c6679bb0..0be9deb4 100644 --- a/Trees/Binary Search Trees.ipynb +++ b/Trees/Binary Search Trees.ipynb @@ -17,9 +17,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class TreeNode:\n", @@ -249,9 +247,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -283,23 +279,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Trees/Tree Representation Implementation (Lists).ipynb b/Trees/Tree Representation Implementation (Lists).ipynb index ad33ac3f..f2502b9b 100644 --- a/Trees/Tree Representation Implementation (Lists).ipynb +++ b/Trees/Tree Representation Implementation (Lists).ipynb @@ -52,23 +52,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Trees/Tree Representation Implementation (Nodes and References).ipynb b/Trees/Tree Representation Implementation (Nodes and References).ipynb index 5ca824e2..c4ae9579 100644 --- a/Trees/Tree Representation Implementation (Nodes and References).ipynb +++ b/Trees/Tree Representation Implementation (Nodes and References).ipynb @@ -11,10 +11,8 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": true - }, + "execution_count": 2, + "metadata": {}, "outputs": [], "source": [ "class BinaryTree(object):\n", @@ -62,10 +60,8 @@ }, { "cell_type": "code", - "execution_count": 35, - "metadata": { - "collapsed": false - }, + "execution_count": 3, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -73,9 +69,9 @@ "text": [ "a\n", "None\n", - "<__main__.BinaryTree object at 0x104779c10>\n", + "<__main__.BinaryTree object at 0x0000020232255320>\n", "b\n", - "<__main__.BinaryTree object at 0x103b42c50>\n", + "<__main__.BinaryTree object at 0x0000020232255278>\n", "c\n", "hello\n" ] @@ -96,27 +92,34 @@ "r.getRightChild().setRootVal('hello')\n", "print(r.getRightChild().getRootVal())" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Trees/Trees Interview Problems - SOLUTIONS/Binary Search Tree Check - SOLUTION.ipynb b/Trees/Trees Interview Problems - SOLUTIONS/Binary Search Tree Check - SOLUTION.ipynb index 1ac09210..666264cc 100644 --- a/Trees/Trees Interview Problems - SOLUTIONS/Binary Search Tree Check - SOLUTION.ipynb +++ b/Trees/Trees Interview Problems - SOLUTIONS/Binary Search Tree Check - SOLUTION.ipynb @@ -19,16 +19,18 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false - }, + "execution_count": 2, + "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" + "ename": "NameError", + "evalue": "name 'tree' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mtree_vals\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0msorted\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtree_vals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0minorder\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtree\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[0msort_check\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtree_vals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mNameError\u001b[0m: name 'tree' is not defined" ] } ], @@ -57,10 +59,8 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": { - "collapsed": false - }, + "execution_count": 3, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -133,23 +133,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/Trees/Trees Interview Problems - SOLUTIONS/Tree Level Order Print - SOLUTION.ipynb b/Trees/Trees Interview Problems - SOLUTIONS/Tree Level Order Print - SOLUTION.ipynb index 9b0ec477..832318e2 100644 --- a/Trees/Trees Interview Problems - SOLUTIONS/Tree Level Order Print - SOLUTION.ipynb +++ b/Trees/Trees Interview Problems - SOLUTIONS/Tree Level Order Print - SOLUTION.ipynb @@ -105,7 +105,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.6.4" } }, "nbformat": 4, diff --git a/Trees/Trees Interview Problems/Binary Search Tree Check.ipynb b/Trees/Trees Interview Problems/Binary Search Tree Check.ipynb index 74a68fe1..a3f043d8 100644 --- a/Trees/Trees Interview Problems/Binary Search Tree Check.ipynb +++ b/Trees/Trees Interview Problems/Binary Search Tree Check.ipynb @@ -20,9 +20,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Code goes Here" @@ -38,23 +36,23 @@ ], "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.11" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 }