diff --git a/arrays_strings/permutation/permutation_solution.ipynb b/arrays_strings/permutation/permutation_solution.ipynb index 8f4589c..6eb4e58 100644 --- a/arrays_strings/permutation/permutation_solution.ipynb +++ b/arrays_strings/permutation/permutation_solution.ipynb @@ -35,6 +35,7 @@ "source": [ "## Constraints\n", "\n", + "* Can we assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -163,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -241,7 +242,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.6" + "version": "2.7.10" } }, "nbformat": 4, diff --git a/arrays_strings/rotation/rotation_challenge.ipynb b/arrays_strings/rotation/rotation_challenge.ipynb index c892cb2..e66ebe3 100644 --- a/arrays_strings/rotation/rotation_challenge.ipynb +++ b/arrays_strings/rotation/rotation_challenge.ipynb @@ -34,6 +34,7 @@ "source": [ "## Constraints\n", "\n", + "* Can you assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -74,38 +75,20 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "def is_substring(substr, s):\n", - " if len(s) < len(substr):\n", - " return False\n", - " elif len(substr) == len(s) and len(s) == 0:\n", - " return True\n", - " pos = 0\n", - " while pos < len(s):\n", - " so_far = 0\n", - " while so_far < len(substr):\n", - " if substr[so_far] != s[pos]:\n", - " pos = pos + 1\n", - " break\n", - " else:\n", - " pos = pos + 1\n", - " so_far = so_far + 1\n", - " if so_far == len(substr):\n", - " return True\n", - " return False\n", + "def is_substring(s1, s2):\n", + " # TODO: Implement me\n", + " pass\n", "\n", "def is_rotation(s1, s2):\n", - " if s1 is None or s2 is None:\n", - " return False\n", - " elif len(s1) != len(s2):\n", - " return False\n", - " else:\n", - " return is_substring(s2,s1+s1)" + " # TODO: Implement me\n", + " # Call is_substring only once\n", + " pass" ] }, { @@ -126,19 +109,11 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Success: test_rotation\n" - ] - } - ], + "outputs": [], "source": [ "# %load test_rotation.py\n", "from nose.tools import assert_equal\n", @@ -188,7 +163,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.6" + "version": "2.7.10" } }, "nbformat": 4, diff --git a/arrays_strings/unique_chars/unique_chars_challenge.ipynb b/arrays_strings/unique_chars/unique_chars_challenge.ipynb index c9ffbff..0e85a04 100644 --- a/arrays_strings/unique_chars/unique_chars_challenge.ipynb +++ b/arrays_strings/unique_chars/unique_chars_challenge.ipynb @@ -34,6 +34,7 @@ "source": [ "## Constraints\n", "\n", + "* Can you assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -72,22 +73,15 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def unique_chars(string):\n", - " from collections import defaultdict\n", - " \n", - " char_table = defaultdict(int)\n", - " for c in string:\n", - " if char_table[c] > 0:\n", - " return False\n", - " else:\n", - " char_table[c] = 1\n", - " return True" + " # TODO: Implement me\n", + " pass" ] }, { @@ -106,19 +100,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Success: test_unique_chars\n" - ] - } - ], + "outputs": [], "source": [ "# %load test_unique_chars.py\n", "from nose.tools import assert_equal\n", @@ -173,7 +159,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.6" + "version": "2.7.10" } }, "nbformat": 4, diff --git a/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb b/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb index b35d575..c8a7f69 100644 --- a/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb +++ b/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb @@ -34,6 +34,7 @@ "source": [ "## Constraints\n", "\n", + "* Is a naiive solution sufficient?\n", " * Yes" ] @@ -67,25 +68,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "def insert(l,item_pos):\n", - " item = l[item_pos]\n", - " while item_pos > 0:\n", - " if l[item_pos - 1] > item:\n", - " l[item_pos - 1], l[item_pos] = l[item_pos], l[item_pos - 1]\n", - " item_pos -= 1\n", - " else:\n", - " break\n", - "\n", "def insertion_sort(data):\n", - " for i,item in enumerate(data):\n", - " insert(data,i)\n", - " return data" + " # TODO: Implement me\n", + " pass" ] }, { @@ -101,22 +92,11 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Empty input\n", - "One element\n", - "Two or more elements\n", - "Success: test_insertion_sort\n" - ] - } - ], + "outputs": [], "source": [ "# %load test_insertion_sort.py\n", "from nose.tools import assert_equal\n", @@ -173,7 +153,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.6" + "version": "2.7.10" } }, "nbformat": 4, diff --git a/sorting_searching/insertion_sort/insertion_sort_solution.ipynb b/sorting_searching/insertion_sort/insertion_sort_solution.ipynb index 3d865e9..83314b7 100644 --- a/sorting_searching/insertion_sort/insertion_sort_solution.ipynb +++ b/sorting_searching/insertion_sort/insertion_sort_solution.ipynb @@ -33,6 +33,7 @@ "source": [ "## Constraints\n", "\n", + "* Is a naiive solution sufficient?\n", " * Yes" ] @@ -151,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -160,34 +161,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "Empty input\n" - ] - }, - { - "ename": "NameError", - "evalue": "global name 'insertion_sort' 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/home/wdonahoe/Documents/interactive-coding-challenges/sorting_searching/insertion_sort/test_insertion_sort.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'__main__'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 25\u001b[0m \u001b[0mtest\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mTestInsertionSort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 26\u001b[1;33m \u001b[0mtest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtest_insertion_sort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m/home/wdonahoe/Documents/interactive-coding-challenges/sorting_searching/insertion_sort/test_insertion_sort.py\u001b[0m in \u001b[0;36mtest_insertion_sort\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Empty input'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0minsertion_sort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m \u001b[0massert_equal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\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;31mNameError\u001b[0m: global name 'insertion_sort' is not defined" + "Empty input\n", + "One element\n", + "Two or more elements\n", + "Success: test_insertion_sort\n" ] } ], "source": [ "%run -i test_insertion_sort.py" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": { @@ -206,7 +189,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.6" + "version": "2.7.10" } }, "nbformat": 4,