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 new file mode 100644 index 00000000..047d0421 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Implement a Doubly Linked List-checkpoint.ipynb @@ -0,0 +1,67 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Doubly Linked List\n", + "\n", + "For this interview problem, implement a node class and show how it can be used to create a doubly linked list." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node(object):\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create a Doubly Linked List here" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "Note that there is no test for this solution (because it would give away the answer structure).\n", + "\n", + "Check out the Implement a Linked List Solution Notebook for the answer to this interview problem, as well as the answer for the implementation of a singly linked list." + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..92b84693 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Implement a Singly Linked List-checkpoint.ipynb @@ -0,0 +1,68 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Singly Linked List\n", + "\n", + "For this interview problem, create a node class and show how it can be used to create a Singly Linked List" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node(object):\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create a Singly Linked List here" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "Note that there is no test for this solution (because it would give away the answer structure).\n", + "\n", + "Check out the Implement a Linked List Solution Notebook for the answer to this interview problem, as well as the answer for the implementation of a doubly linked list." + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..de16594d --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Nth to Last Node -checkpoint.ipynb @@ -0,0 +1,186 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Linked List Nth to Last Node \n", + "\n", + "## Problem Statement\n", + "Write a function that takes a head node and an integer value **n** and then returns the nth to last node in the linked list. For example, given:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node:\n", + "\n", + " def __init__(self, value):\n", + " self.value = value\n", + " self.nextnode = None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Example Input and Output:**" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "d = Node(4)\n", + "e = Node(5)\n", + "\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = d\n", + "d.nextnode = e\n", + "\n", + "# This would return the node d with a value of 4, because its the 2nd to last node.\n", + "target_node = nth_to_last_node(2, a) " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "target_node.value" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Solution\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def nth_to_last_node(n, head):\n", + "\n", + " pass" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION AGAINST A TEST CASE \n", + "\n", + "PLEASE NOTE THIS IS JUST ONE CASE\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "d = Node(4)\n", + "e = Node(5)\n", + "\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = d\n", + "d.nextnode = e\n", + "\n", + "####\n", + "\n", + "class TestNLast(object):\n", + " \n", + " def test(self,sol):\n", + " \n", + " assert_equal(sol(2,a),d)\n", + " print 'ALL TEST CASES PASSED'\n", + " \n", + "# Run tests\n", + "t = TestNLast()\n", + "t.test(nth_to_last_node)" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..d6d333eb --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Linked List Reversal -checkpoint.ipynb @@ -0,0 +1,244 @@ +{ + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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 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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..8c41dde7 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/.ipynb_checkpoints/Singly Linked List Cycle Check-checkpoint.ipynb @@ -0,0 +1,147 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Singly Linked List Cycle Check \n", + "\n", + "## Problem\n", + "\n", + "Given a singly linked list, write a function which takes in the first node in a singly linked list and returns a boolean indicating if the linked list contains a \"cycle\".\n", + "\n", + "A cycle is when a node's next point actually points back to a previous node in the list. This is also sometimes known as a circularly linked list.\n", + "\n", + "You've been given the Linked List Node class code:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "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:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def cycle_check(node):\n", + "\n", + " pass #Your function should return a boolean" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "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", + "# CREATE CYCLE LIST\n", + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = a # Cycle Here!\n", + "\n", + "\n", + "# CREATE NON CYCLE LIST\n", + "x = Node(1)\n", + "y = Node(2)\n", + "z = Node(3)\n", + "\n", + "x.nextnode = y\n", + "y.nextnode = z\n", + "\n", + "\n", + "#############\n", + "class TestCycleCheck(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol(a),True)\n", + " assert_equal(sol(x),False)\n", + " \n", + " print \"ALL TEST CASES PASSED\"\n", + " \n", + "# Run Tests\n", + "\n", + "t = TestCycleCheck()\n", + "t.test(cycle_check)\n" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..047d0421 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Implement a Doubly Linked List.ipynb @@ -0,0 +1,67 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Doubly Linked List\n", + "\n", + "For this interview problem, implement a node class and show how it can be used to create a doubly linked list." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node(object):\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create a Doubly Linked List here" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "Note that there is no test for this solution (because it would give away the answer structure).\n", + "\n", + "Check out the Implement a Linked List Solution Notebook for the answer to this interview problem, as well as the answer for the implementation of a singly linked list." + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..92b84693 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Implement a Singly Linked List.ipynb @@ -0,0 +1,68 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Singly Linked List\n", + "\n", + "For this interview problem, create a node class and show how it can be used to create a Singly Linked List" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node(object):\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Create a Singly Linked List here" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution\n", + "\n", + "Note that there is no test for this solution (because it would give away the answer structure).\n", + "\n", + "Check out the Implement a Linked List Solution Notebook for the answer to this interview problem, as well as the answer for the implementation of a doubly linked list." + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..de16594d --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Nth to Last Node .ipynb @@ -0,0 +1,186 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Linked List Nth to Last Node \n", + "\n", + "## Problem Statement\n", + "Write a function that takes a head node and an integer value **n** and then returns the nth to last node in the linked list. For example, given:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Node:\n", + "\n", + " def __init__(self, value):\n", + " self.value = value\n", + " self.nextnode = None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Example Input and Output:**" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "d = Node(4)\n", + "e = Node(5)\n", + "\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = d\n", + "d.nextnode = e\n", + "\n", + "# This would return the node d with a value of 4, because its the 2nd to last node.\n", + "target_node = nth_to_last_node(2, a) " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "target_node.value" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Solution\n", + "Fill out your solution below:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def nth_to_last_node(n, head):\n", + "\n", + " pass" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ALL TEST CASES PASSED\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "RUN THIS CELL TO TEST YOUR SOLUTION AGAINST A TEST CASE \n", + "\n", + "PLEASE NOTE THIS IS JUST ONE CASE\n", + "\"\"\"\n", + "\n", + "from nose.tools import assert_equal\n", + "\n", + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "d = Node(4)\n", + "e = Node(5)\n", + "\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = d\n", + "d.nextnode = e\n", + "\n", + "####\n", + "\n", + "class TestNLast(object):\n", + " \n", + " def test(self,sol):\n", + " \n", + " assert_equal(sol(2,a),d)\n", + " print 'ALL TEST CASES PASSED'\n", + " \n", + "# Run tests\n", + "t = TestNLast()\n", + "t.test(nth_to_last_node)" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..d6d333eb --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Linked List Reversal .ipynb @@ -0,0 +1,244 @@ +{ + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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 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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..8c41dde7 --- /dev/null +++ b/Linked Lists/Linked Lists Interview Problems/Linked List Interview Problems/Singly Linked List Cycle Check.ipynb @@ -0,0 +1,147 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Singly Linked List Cycle Check \n", + "\n", + "## Problem\n", + "\n", + "Given a singly linked list, write a function which takes in the first node in a singly linked list and returns a boolean indicating if the linked list contains a \"cycle\".\n", + "\n", + "A cycle is when a node's next point actually points back to a previous node in the list. This is also sometimes known as a circularly linked list.\n", + "\n", + "You've been given the Linked List Node class code:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "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:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def cycle_check(node):\n", + "\n", + " pass #Your function should return a boolean" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test Your Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "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", + "# CREATE CYCLE LIST\n", + "a = Node(1)\n", + "b = Node(2)\n", + "c = Node(3)\n", + "\n", + "a.nextnode = b\n", + "b.nextnode = c\n", + "c.nextnode = a # Cycle Here!\n", + "\n", + "\n", + "# CREATE NON CYCLE LIST\n", + "x = Node(1)\n", + "y = Node(2)\n", + "z = Node(3)\n", + "\n", + "x.nextnode = y\n", + "y.nextnode = z\n", + "\n", + "\n", + "#############\n", + "class TestCycleCheck(object):\n", + " \n", + " def test(self,sol):\n", + " assert_equal(sol(a),True)\n", + " assert_equal(sol(x),False)\n", + " \n", + " print \"ALL TEST CASES PASSED\"\n", + " \n", + "# Run Tests\n", + "\n", + "t = TestCycleCheck()\n", + "t.test(cycle_check)\n" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..df89907a --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 1 - SOLUTION-checkpoint.ipynb @@ -0,0 +1,127 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 - SOLUTION\n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls 1 to 7 (with uniform probability), simulate a 5 sided dice. Preferably, write your solution as a function. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've solved it on pen and paper! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SOLUTION\n", + "\n", + "This is a new problem we haven't seen directly before! Many times this question is asked in the form of functions e.g. your given a function random_7() and you have to take it as an input and create random_5()\n", + "\n", + "The key to solving this problem is to make sure you focus on the requirement that the final distribution of the rolls be uniform, also you were not given any requirements on Time and Space, so the solution is actually *very* simple, just keep re-rolling if you get a number greater than 5!\n", + "\n", + "We can code this out:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from random import randint\n", + " \n", + "def dice7():\n", + " return randint(1, 7)\n", + " \n", + "# Our Solution\n", + "def convert7to5():\n", + " \n", + " # Starting roll (just needs to be larger than 5)\n", + " roll = 7\n", + " \n", + " while roll > 5:\n", + " \n", + " roll = dice7()\n", + " print 'dice7() produced a roll of ',roll\n", + " print ' Your final returned roll is below:'\n", + " return roll" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dice7() produced a roll of 7\n", + "dice7() produced a roll of 5\n", + " Your final returned roll is below:\n" + ] + }, + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "convert7to5()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, the next problem (On-Site Question 2) will be harder, the reverse conversion of rolls! This question should serve as a reminder not to overthink the solution to a question! Keep in mind that our solution has the potential to run for infinity if we keep rolling 6s and 7s (although this is highly unlikely).\n", + "\n", + "## 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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..6d44e71a --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 2 - SOLUTION-checkpoint.ipynb @@ -0,0 +1,149 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 - SOLUTION\n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls from 1 to 5, simulate a uniform 7 sided dice! **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've come up with a solution by hand! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SOLUTION\n", + "\n", + "Because the 5 sided dice can not produce 7 possible outcomes on a single roll, we immediately know that we need to roll the dice at least twice. \n", + "\n", + "If we roll the dice twice we have 25 possible combinations of the results of the two rolls. While 25 is not divisible by 7, 21 is. This means we can implement our previous strategy of throwing out rolls not in our intended range.\n", + "\n", + "It's also important to note that we can't expand the solution to implement more rolls in order to not throw any out, because 5 and 7 are both prime which means that no exponent of 5 will be divisible by 7 no matter how high you go.\n", + "\n", + "We will define our range as a section of the 25 possible combinations of rolls. A good way to do this is by converting the two rolls into a unique outcome number in the range 1 through 25.\n", + "\n", + "We will create this number by taking the rolls, then we take the first roll and after subtracting 1 from it we multiply it by 4. Now the first roll corresponds with a value of 1 - 20.\n", + "\n", + "Then we take the second roll and add it to the result of the first manipulation. Giving us a range of 1-25.\n", + "\n", + "So our final solution is to roll the dice twice. Check the manipulated range from 1 to 25, if its greater than 21, do a reroll. Let's see it in action:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from random import randint\n", + " \n", + "def dice5():\n", + " return randint(1, 5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now for our conversion function:" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def convert5to7():\n", + "\n", + " # For constant re-roll purposes\n", + " while True:\n", + "\n", + " # Roll the dice twice\n", + " roll_1 = dice5()\n", + " roll_2 = dice5()\n", + " \n", + " #print 'The rolls were {} and {}'.format(roll_1,roll_2)\n", + "\n", + " # Convert the combination to the range 1 to 25\n", + " num = ( (roll_1-1) * 5 ) + ( roll_2 ) \n", + "\n", + " #print 'The converted range number was:',num\n", + " if num > 21:\n", + "\n", + " # re-roll if we are out of range\n", + " continue\n", + "\n", + " return num %7 + 1 " + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "convert5to7()" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..1e53ad72 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 3 -SOLUTION-checkpoint.ipynb @@ -0,0 +1,91 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 - SOLUTION\n", + "\n", + "## Question\n", + "\n", + "**Given a string, write a function that uses recursion to reverse it. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST use pen and paper or a whiteboard to answer this, no coding allowed! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SOLUTION\n", + "\n", + "Hopefully you remember this problem, you've already seen it! The solution is:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def reverse(s):\n", + " \n", + " # Base Case\n", + " if len(s) <= 1:\n", + " return s\n", + "\n", + " # Recursion\n", + " return reverse(s[1:]) + s[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___\n", + "## Notes\n", + "\n", + "Remember when recursion questions arise, think about the base case and the recursive case. Review the recusion section of the course for review for this problem." + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..8c32f0a1 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/.ipynb_checkpoints/On-Site Question 4 - SOLUTION-checkpoint.ipynb @@ -0,0 +1,263 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 4 - SOLUTION\n", + "\n", + "## Question\n", + "**Find the squareroot of a given number rounded down to the nearest integer, without using the sqrt function. For example, squareroot of a number between [9, 15] should return 3, and [16, 24] should be 4.**\n", + "\n", + "## Requirements\n", + "\n", + "** Feel free to code this out (but its recommended that you use paper/pencil or whiteboard)**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## Solution\n", + "\n", + "The squareroot of a (non-negative) number N always lies between 0 and N/2. The straightforward way to solve this problem would be to check every number k between 0 and N/2, until the square of k becomes greater than or rqual to N. If k^2 becomes equal to N, then we return k. Otherwise, we return k-1 because we're rounding down. Here's the code:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def solution(num): \n", + " if num<0: \n", + " raise ValueError \n", + " if num==1: \n", + " return 1 \n", + " for k in range(1+(num/2)): \n", + " if k**2==num: \n", + " return k \n", + " elif k**2>num: \n", + " return k-1 \n", + " return k " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solution(14)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solution(15)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solution(16)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The complexity of this approach is O(N), because we have to check N/2 numbers in the worst case. This linear algorithm is pretty inefficient, we can use some sort of binary search to speed it up. We know that the result is between 0 and N/2, so we can first try N/4 to see whether its square is less than, greater than, or equal to N. If it’s equal then we simply return that value. If it’s less, then we continue our search between N/4 and N/2. Otherwise if it’s greater, then we search between 0 and N/4. In both cases we reduce the potential range by half and continue, this is the logic of binary search. We’re not performing regular binary search though, it’s modified. We want to ensure that we stop at a number k, where k^2<=N but (k+1)^2>N. For example:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def better_solution(num): \n", + " if num<0: \n", + " raise ValueError \n", + " if num==1: \n", + " return 1 \n", + " low=0 \n", + " high=1+(num/2) \n", + " \n", + " while low+1\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + " Fib(n=15000)\n", + "\n", + "\n", + "loops\n", + "recursion\n", + "generators\n", + "memoization\n", + "memoization as decorator\n", + "\n", + "\n", + "45\n", + "87\n", + "58\n", + "44\n", + "43\n", + "\n", + "\n", + "47\n", + "88\n", + "58\n", + "42\n", + "42\n", + "\n", + "\n", + "51\n", + "92\n", + "60\n", + "44\n", + "43\n", + "\n", + "\n", + "43\n", + "87\n", + "58\n", + "42\n", + "43\n", + "\n", + "\n", + "48\n", + "92\n", + "61\n", + "42\n", + "44\n", + "\n", + "\n", + "45\n", + "87\n", + "59\n", + "43\n", + "44\n", + "\n", + "\n", + "44\n", + "85\n", + "57\n", + "42\n", + "44\n", + "\n", + "\n", + "44\n", + "87\n", + "62\n", + "43\n", + "43\n", + "\n", + "\n", + "48\n", + "86\n", + "59\n", + "42\n", + "43\n", + "\n", + "\n", + "45\n", + "91\n", + "61\n", + "45\n", + "45\n", + "\n", + "\n", + "46\n", + "88.2\n", + "59.3\n", + "42.9\n", + "43.4 (Avg)\n", + "\n", + "\n", + "" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..df89907a --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 1 - SOLUTION.ipynb @@ -0,0 +1,127 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 - SOLUTION\n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls 1 to 7 (with uniform probability), simulate a 5 sided dice. Preferably, write your solution as a function. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've solved it on pen and paper! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SOLUTION\n", + "\n", + "This is a new problem we haven't seen directly before! Many times this question is asked in the form of functions e.g. your given a function random_7() and you have to take it as an input and create random_5()\n", + "\n", + "The key to solving this problem is to make sure you focus on the requirement that the final distribution of the rolls be uniform, also you were not given any requirements on Time and Space, so the solution is actually *very* simple, just keep re-rolling if you get a number greater than 5!\n", + "\n", + "We can code this out:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from random import randint\n", + " \n", + "def dice7():\n", + " return randint(1, 7)\n", + " \n", + "# Our Solution\n", + "def convert7to5():\n", + " \n", + " # Starting roll (just needs to be larger than 5)\n", + " roll = 7\n", + " \n", + " while roll > 5:\n", + " \n", + " roll = dice7()\n", + " print 'dice7() produced a roll of ',roll\n", + " print ' Your final returned roll is below:'\n", + " return roll" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dice7() produced a roll of 7\n", + "dice7() produced a roll of 5\n", + " Your final returned roll is below:\n" + ] + }, + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "convert7to5()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, the next problem (On-Site Question 2) will be harder, the reverse conversion of rolls! This question should serve as a reminder not to overthink the solution to a question! Keep in mind that our solution has the potential to run for infinity if we keep rolling 6s and 7s (although this is highly unlikely).\n", + "\n", + "## 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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..b3c51b99 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 2 - SOLUTION.ipynb @@ -0,0 +1,149 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 - SOLUTION\n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls from 1 to 5, simulate a uniform 7 sided dice! **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've come up with a solution by hand! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SOLUTION\n", + "\n", + "Because the 5 sided dice can not produce 7 possible outcomes on a single roll, we immediately know that we need to roll the dice at least twice. \n", + "\n", + "If we roll the dice twice we have 25 possible combinations of the results of the two rolls. While 25 is not divisible by 7, 21 is. This means we can implement our previous strategy of throwing out rolls not in our intended range.\n", + "\n", + "It's also important to note that we can't expand the solution to implement more rolls in order to not throw any out, because 5 and 7 are both prime which means that no exponent of 5 will be divisible by 7 no matter how high you go.\n", + "\n", + "We will define our range as a section of the 25 possible combinations of rolls. A good way to do this is by converting the two rolls into a unique outcome number in the range 1 through 25.\n", + "\n", + "We will create this number by taking the rolls, then we take the first roll and after subtracting 1 from it we multiply it by 5. Now the first roll corresponds with a value of 0, 5, 10, 15 and 20.\n", + "\n", + "Then we take the second roll and add it to the result of the first manipulation. Giving us a range of 1-25.\n", + "\n", + "So our final solution is to roll the dice twice. Check the manipulated range from 1 to 25, if its greater than 21, do a reroll. Let's see it in action:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from random import randint\n", + " \n", + "def dice5():\n", + " return randint(1, 5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now for our conversion function:" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def convert5to7():\n", + "\n", + " # For constant re-roll purposes\n", + " while True:\n", + "\n", + " # Roll the dice twice\n", + " roll_1 = dice5()\n", + " roll_2 = dice5()\n", + " \n", + " #print 'The rolls were {} and {}'.format(roll_1,roll_2)\n", + "\n", + " # Convert the combination to the range 1 to 25\n", + " num = ( (roll_1-1) * 5 ) + ( roll_2 ) \n", + "\n", + " #print 'The converted range number was:',num\n", + " if num > 21:\n", + "\n", + " # re-roll if we are out of range\n", + " continue\n", + "\n", + " return num %7 + 1 " + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "convert5to7()" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..1e53ad72 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 3 -SOLUTION.ipynb @@ -0,0 +1,91 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 - SOLUTION\n", + "\n", + "## Question\n", + "\n", + "**Given a string, write a function that uses recursion to reverse it. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST use pen and paper or a whiteboard to answer this, no coding allowed! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SOLUTION\n", + "\n", + "Hopefully you remember this problem, you've already seen it! The solution is:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def reverse(s):\n", + " \n", + " # Base Case\n", + " if len(s) <= 1:\n", + " return s\n", + "\n", + " # Recursion\n", + " return reverse(s[1:]) + s[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___\n", + "## Notes\n", + "\n", + "Remember when recursion questions arise, think about the base case and the recursive case. Review the recusion section of the course for review for this problem." + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..8c32f0a1 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems - SOLUTIONS/On-Site Question 4 - SOLUTION.ipynb @@ -0,0 +1,263 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 4 - SOLUTION\n", + "\n", + "## Question\n", + "**Find the squareroot of a given number rounded down to the nearest integer, without using the sqrt function. For example, squareroot of a number between [9, 15] should return 3, and [16, 24] should be 4.**\n", + "\n", + "## Requirements\n", + "\n", + "** Feel free to code this out (but its recommended that you use paper/pencil or whiteboard)**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## Solution\n", + "\n", + "The squareroot of a (non-negative) number N always lies between 0 and N/2. The straightforward way to solve this problem would be to check every number k between 0 and N/2, until the square of k becomes greater than or rqual to N. If k^2 becomes equal to N, then we return k. Otherwise, we return k-1 because we're rounding down. Here's the code:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def solution(num): \n", + " if num<0: \n", + " raise ValueError \n", + " if num==1: \n", + " return 1 \n", + " for k in range(1+(num/2)): \n", + " if k**2==num: \n", + " return k \n", + " elif k**2>num: \n", + " return k-1 \n", + " return k " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solution(14)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solution(15)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "solution(16)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The complexity of this approach is O(N), because we have to check N/2 numbers in the worst case. This linear algorithm is pretty inefficient, we can use some sort of binary search to speed it up. We know that the result is between 0 and N/2, so we can first try N/4 to see whether its square is less than, greater than, or equal to N. If it’s equal then we simply return that value. If it’s less, then we continue our search between N/4 and N/2. Otherwise if it’s greater, then we search between 0 and N/4. In both cases we reduce the potential range by half and continue, this is the logic of binary search. We’re not performing regular binary search though, it’s modified. We want to ensure that we stop at a number k, where k^2<=N but (k+1)^2>N. For example:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def better_solution(num): \n", + " if num<0: \n", + " raise ValueError \n", + " if num==1: \n", + " return 1 \n", + " low=0 \n", + " high=1+(num/2) \n", + " \n", + " while low+1\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + " Fib(n=15000)\n", + "\n", + "\n", + "loops\n", + "recursion\n", + "generators\n", + "memoization\n", + "memoization as decorator\n", + "\n", + "\n", + "45\n", + "87\n", + "58\n", + "44\n", + "43\n", + "\n", + "\n", + "47\n", + "88\n", + "58\n", + "42\n", + "42\n", + "\n", + "\n", + "51\n", + "92\n", + "60\n", + "44\n", + "43\n", + "\n", + "\n", + "43\n", + "87\n", + "58\n", + "42\n", + "43\n", + "\n", + "\n", + "48\n", + "92\n", + "61\n", + "42\n", + "44\n", + "\n", + "\n", + "45\n", + "87\n", + "59\n", + "43\n", + "44\n", + "\n", + "\n", + "44\n", + "85\n", + "57\n", + "42\n", + "44\n", + "\n", + "\n", + "44\n", + "87\n", + "62\n", + "43\n", + "43\n", + "\n", + "\n", + "48\n", + "86\n", + "59\n", + "42\n", + "43\n", + "\n", + "\n", + "45\n", + "91\n", + "61\n", + "45\n", + "45\n", + "\n", + "\n", + "46\n", + "88.2\n", + "59.3\n", + "42.9\n", + "43.4 (Avg)\n", + "\n", + "\n", + "" + ] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..c4514711 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 \n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls 1 to 7 (with uniform probability), simulate a 5 sided dice. Preferably, write your solution as a function. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've solved it on pen and paper! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..a63ca005 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 \n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls from 1 to 5, simulate a uniform 7 sided dice! **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've come up with a solution by hand! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..49a04c0d --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 \n", + "\n", + "## Question\n", + "\n", + "**Given a string, write a function that uses recursion to reverse it. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST use pen and paper or a whiteboard to answer this, no coding allowed! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..d69bf130 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/.ipynb_checkpoints/On-Site Question 4 -checkpoint.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 4 \n", + "\n", + "## Question\n", + "**Find the squareroot of a given number rounded down to the nearest integer, without using the sqrt function. For example, squareroot of a number between [9, 15] should return 3, and [16, 24] should be 4.**\n", + "\n", + "## Requirements\n", + "\n", + "** Feel free to code this out (but its recommended that you use paper/pencil or whiteboard)**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..8edb0203 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/.ipynb_checkpoints/Phone Screen-checkpoint.ipynb @@ -0,0 +1,80 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phone Screen\n", + "\n", + "**This phone screen will consist of a non-technical series of questions about you and the company, and then a second half of a simple technical question to be coded out**\n", + "___\n", + "## Non-Technical Questions\n", + "\n", + "**Answer the following questions (2-5 minute responses) technical answers not required, more interested in hearing about your reasoning**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Give me some quick background about you (go over your resume)\n", + "* Why do you want to work here?\n", + "* What's your favorite programming language and why?\n", + "* Where do you see yourself in 5 years?\n", + "* Do you have any questions about the company for me?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___\n", + "## Technical Questions\n", + "\n", + "**Answer the following question in the *Markdown* cell below. It's important to note that the cell below does NOT have syntax highlighting, its common in a phone screen interview to be given a text editor hich doesn't have anything more than basic text support**\n", + "\n", + "1. Write a function that computes the Nth fibonacci number" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..c4514711 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/On-Site Question 1 .ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 \n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls 1 to 7 (with uniform probability), simulate a 5 sided dice. Preferably, write your solution as a function. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've solved it on pen and paper! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..a63ca005 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/On-Site Question 2 .ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 \n", + "___\n", + "\n", + "## Question\n", + "** Given a dice which rolls from 1 to 5, simulate a uniform 7 sided dice! **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST do this on pen and paper or on a whiteboard. No actual coding is allowed until you've come up with a solution by hand! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..49a04c0d --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/On-Site Question 3 .ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 \n", + "\n", + "## Question\n", + "\n", + "**Given a string, write a function that uses recursion to reverse it. **\n", + "\n", + "## Requirements\n", + "\n", + "** You MUST use pen and paper or a whiteboard to answer this, no coding allowed! **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "____" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..d69bf130 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/On-Site Question 4 .ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 4 \n", + "\n", + "## Question\n", + "**Find the squareroot of a given number rounded down to the nearest integer, without using the sqrt function. For example, squareroot of a number between [9, 15] should return 3, and [16, 24] should be 4.**\n", + "\n", + "## Requirements\n", + "\n", + "** Feel free to code this out (but its recommended that you use paper/pencil or whiteboard)**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..8edb0203 --- /dev/null +++ b/Mock Interviews/Large Search Engine Company/Search Engine Company - Interview Problems/Phone Screen.ipynb @@ -0,0 +1,80 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phone Screen\n", + "\n", + "**This phone screen will consist of a non-technical series of questions about you and the company, and then a second half of a simple technical question to be coded out**\n", + "___\n", + "## Non-Technical Questions\n", + "\n", + "**Answer the following questions (2-5 minute responses) technical answers not required, more interested in hearing about your reasoning**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Give me some quick background about you (go over your resume)\n", + "* Why do you want to work here?\n", + "* What's your favorite programming language and why?\n", + "* Where do you see yourself in 5 years?\n", + "* Do you have any questions about the company for me?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___\n", + "## Technical Questions\n", + "\n", + "**Answer the following question in the *Markdown* cell below. It's important to note that the cell below does NOT have syntax highlighting, its common in a phone screen interview to be given a text editor hich doesn't have anything more than basic text support**\n", + "\n", + "1. Write a function that computes the Nth fibonacci number" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..ccfa72f7 --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/.ipynb_checkpoints/On-Site Question 1 -checkpoint.ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 \n", + "\n", + "## Problem\n", + "\n", + "** Given a list of integers, find the largest product you could make from 3 integers in the list **\n", + "\n", + "## Requirements\n", + "\n", + "** You can assume that the list will always have at least 3 integers **\n", + "\n", + "** Paper/pencil only, don't code this out until you've solved it as far as you can by hand. **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..cd47095c --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/.ipynb_checkpoints/On-Site Question 2 -checkpoint.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 \n", + "\n", + "## Problem\n", + "\n", + "** Write a function that given a target amount of money and a list of possible coin denominations, returns the number of ways to make change for the target amount using the coin denominations**\n", + "\n", + "## Requirements\n", + "\n", + "** Write out your work on paper/pencil, then see if you can code up your solution **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..380ec415 --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/.ipynb_checkpoints/On-Site Question 3 -checkpoint.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 \n", + "\n", + "## Problem\n", + "\n", + "** Given a binary tree, check whether it’s a binary search tree or not. **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Requirements\n", + "\n", + "** Use paper/pencil, do not code this in an IDE until you've done it manually**\n", + "\n", + "** Do not use built-in Python libraries to do this, but do mention them if you know about them **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..062944af --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/.ipynb_checkpoints/Phone Screen -checkpoint.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phone Screen \n", + "\n", + "## Problem\n", + "\n", + "** If you were given a list of n integers and knew that they were sorted, how quickly could you check if a given integer was in the list? Elaborate on your reasoning and search methods in general**\n", + "\n", + "## Requirements\n", + "\n", + "** Try explaining your solution to someone and see if it makes sense ot them. Don't code anything for this problem **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..ccfa72f7 --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/On-Site Question 1 .ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 \n", + "\n", + "## Problem\n", + "\n", + "** Given a list of integers, find the largest product you could make from 3 integers in the list **\n", + "\n", + "## Requirements\n", + "\n", + "** You can assume that the list will always have at least 3 integers **\n", + "\n", + "** Paper/pencil only, don't code this out until you've solved it as far as you can by hand. **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..cd47095c --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/On-Site Question 2 .ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 \n", + "\n", + "## Problem\n", + "\n", + "** Write a function that given a target amount of money and a list of possible coin denominations, returns the number of ways to make change for the target amount using the coin denominations**\n", + "\n", + "## Requirements\n", + "\n", + "** Write out your work on paper/pencil, then see if you can code up your solution **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..380ec415 --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/On-Site Question 3 .ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 \n", + "\n", + "## Problem\n", + "\n", + "** Given a binary tree, check whether it’s a binary search tree or not. **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Requirements\n", + "\n", + "** Use paper/pencil, do not code this in an IDE until you've done it manually**\n", + "\n", + "** Do not use built-in Python libraries to do this, but do mention them if you know about them **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..062944af --- /dev/null +++ b/Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions/Phone Screen .ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phone Screen \n", + "\n", + "## Problem\n", + "\n", + "** If you were given a list of n integers and knew that they were sorted, how quickly could you check if a given integer was in the list? Elaborate on your reasoning and search methods in general**\n", + "\n", + "## Requirements\n", + "\n", + "** Try explaining your solution to someone and see if it makes sense ot them. Don't code anything for this problem **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..a72a4672 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/.ipynb_checkpoints/On-Site Question 1-checkpoint.ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 \n", + "\n", + "## Problem\n", + "\n", + "** Given a list of integers and a target number, write a function that returns a boolean indicating if its possible to sum two integers from the list to reach the target number **\n", + "\n", + "## Requirements\n", + "\n", + "** Try pen/paper before coding out your solution **\n", + "\n", + "** You can not use an integer element twice. Optimize for time over space **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..e65f70c4 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/.ipynb_checkpoints/On-Site Question 2-checkpoint.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 \n", + "\n", + "## Problem\n", + "\n", + "** Given a list of account ID numbers (integers) which contains duplicates , find the one unique integer. (the list is guaranteed to only have one unique (non-duplicated) integer **\n", + "\n", + "## Requirements\n", + "\n", + "** Do not use built-in Python functions or methods **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..139bd6c5 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/.ipynb_checkpoints/On-Site Question 3-checkpoint.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 \n", + "\n", + "## Problem\n", + "\n", + "** Create a function that takes in a list of unsorted prices (integers) and a maximum possible price value, and return a sorted list of prices**\n", + "\n", + "## Requirements\n", + "\n", + "** Your function should be able to perform this in less than O(nlogn) time. **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..d082e4e5 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/.ipynb_checkpoints/Phone Screen -checkpoint.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phone Screen \n", + "\n", + "## Problem \n", + "\n", + "** Remove duplicate characters in a given string keeping only the first occurrences. For example, if the input is ‘tree traversal’ the output will be ‘tre avsl’. **\n", + "\n", + "## Requirements\n", + "\n", + "**Complete this problem on a text editor that does not have syntax highlighting, such as a goolge doc!**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..a72a4672 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/On-Site Question 1.ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 1 \n", + "\n", + "## Problem\n", + "\n", + "** Given a list of integers and a target number, write a function that returns a boolean indicating if its possible to sum two integers from the list to reach the target number **\n", + "\n", + "## Requirements\n", + "\n", + "** Try pen/paper before coding out your solution **\n", + "\n", + "** You can not use an integer element twice. Optimize for time over space **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..e65f70c4 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/On-Site Question 2.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 2 \n", + "\n", + "## Problem\n", + "\n", + "** Given a list of account ID numbers (integers) which contains duplicates , find the one unique integer. (the list is guaranteed to only have one unique (non-duplicated) integer **\n", + "\n", + "## Requirements\n", + "\n", + "** Do not use built-in Python functions or methods **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..139bd6c5 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/On-Site Question 3.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# On-Site Question 3 \n", + "\n", + "## Problem\n", + "\n", + "** Create a function that takes in a list of unsorted prices (integers) and a maximum possible price value, and return a sorted list of prices**\n", + "\n", + "## Requirements\n", + "\n", + "** Your function should be able to perform this in less than O(nlogn) time. **" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..d082e4e5 --- /dev/null +++ b/Mock Interviews/Social Network Company/Social Network Company - Interview Questions/Phone Screen .ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phone Screen \n", + "\n", + "## Problem \n", + "\n", + "** Remove duplicate characters in a given string keeping only the first occurrences. For example, if the input is ‘tree traversal’ the output will be ‘tre avsl’. **\n", + "\n", + "## Requirements\n", + "\n", + "**Complete this problem on a text editor that does not have syntax highlighting, such as a goolge doc!**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Good Luck!" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..405b8032 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/.ipynb_checkpoints/Bridge Crossing-checkpoint.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bridge Crossing" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Problem Statement\n", + "\n", + "A group of four travelers comes to a bridge at night. The bridge can hold the weight of at most only two of the travelers at a time, and it can- not be crossed without using a flashlight. \n", + "\n", + "The travelers have one flashlight among them. Each traveler walks at a different speed: The first can cross the bridge in 1 minute, the second in 2 minutes, the third in 5 minutes, and the fourth takes 10 minutes to cross the bridge. If two travelers cross together, they walk at the speed of the slower traveler.\n", + "\n", + "What is the least amount of time in which all the travelers can cross from one side of the bridge to the other?\n", + "\n" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..15461219 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/.ipynb_checkpoints/Coins and a Scale -checkpoint.ipynb @@ -0,0 +1,35 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Coins and a Scale \n", + "## Problem Statement\n", + "\n", + "You have eight coins and a two-pan scale. All the coins weigh the same, **except for one** which is heavier than all the others. The coins are otherwise indistinguishable. You may make no assumptions about how much heavier the heavy coin is. What is the minimum number of weighings needed to be certain of identifying the heavy coin?" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..cbe1be74 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/.ipynb_checkpoints/Egg Drop -checkpoint.ipynb @@ -0,0 +1,38 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Egg Drop \n", + "This is probably the most common brain teaser riddle out of the group, so really try to think algorithmically about this problem before looking at the solution!\n", + "## Problem Statement\n", + "\n", + "A tower has 100 floors. You've been given two eggs. The eggs are strong enough that they can be dropped from a particular floor in the tower without breaking. You've been tasked to find the highest floor an egg can be dropped without breaking, in as few drops as possible. If an egg is dropped from above its target floor it will break. If it is dropped from that floor or below, it will be intact and you can test drop the egg again on another floor.\n", + "\n", + "Show algorithmically how you would go about doing this in as few drops as possible. (Your answer should be a number of the fewest drops needed for testing 2 eggs on 100 floors)" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..402bfffd --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/.ipynb_checkpoints/Hallway Lockers-checkpoint.ipynb @@ -0,0 +1,35 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Hallway Lockers\n", + "## Problem Statement\n", + "\n", + "You are in a hallway lined with 100 lockers. You start with one pass and open the lockers, so that the *opened* lockers are now with their doors opened out. You begin by closing **every second** locker. Then you go to close **every third** locker and **close it if it is open or open it if it’s closed** — we will refer to this as \"toggling\" the lockers. You continue toggling every nth locker on pass number n. After your hundredth pass of the hallway, in which you toggle only locker number 100, how many lockers are open?\n" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..727614de --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/.ipynb_checkpoints/Jugs of Water -checkpoint.ipynb @@ -0,0 +1,35 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Jugs of Water \n", + "## Problem Statement\n", + "\n", + "You have a five gallons jug and a three gallons jug, and an unlimited supply of water (but no measuring cups) How would you come up with exactly four gallons of water?" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..b3b8995a --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/.ipynb_checkpoints/Light Switches -checkpoint.ipynb @@ -0,0 +1,37 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Light Switches\n", + "## Problem Statement\n", + "\n", + "You are in a hallway next to three light switches, all of which are off. Each switch activates a different *incandescent* light bulb in the room at the end of the hall. You cannot see the lights from where the switches are. Your task is to determine which light corresponds to each switch. However, you may go into the room with the lights only once.\n", + "\n", + "**Note: This is a bit of \"trick\" question, so don't spend too much time on it. Although it is more on the \"fun\" side of brain teaser type questions.**\n" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..c9f81f96 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/.ipynb_checkpoints/Ropes Burning-checkpoint.ipynb @@ -0,0 +1,39 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Ropes Burning \n", + "## Problem Statement\n", + "\n", + "You have two ropes. Each takes exactly 60 minutes to burn.\n", + "\n", + "They are made of different material so even though they take the same amount of time to burn, they burn at separate rates. In addition, each rope burns inconsistently.\n", + "\n", + "How do you measure out exactly 45 minutes?" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems/Bridge Crossing.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Bridge Crossing.ipynb new file mode 100644 index 00000000..405b8032 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Bridge Crossing.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bridge Crossing" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Problem Statement\n", + "\n", + "A group of four travelers comes to a bridge at night. The bridge can hold the weight of at most only two of the travelers at a time, and it can- not be crossed without using a flashlight. \n", + "\n", + "The travelers have one flashlight among them. Each traveler walks at a different speed: The first can cross the bridge in 1 minute, the second in 2 minutes, the third in 5 minutes, and the fourth takes 10 minutes to cross the bridge. If two travelers cross together, they walk at the speed of the slower traveler.\n", + "\n", + "What is the least amount of time in which all the travelers can cross from one side of the bridge to the other?\n", + "\n" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..15461219 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Coins and a Scale .ipynb @@ -0,0 +1,35 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Coins and a Scale \n", + "## Problem Statement\n", + "\n", + "You have eight coins and a two-pan scale. All the coins weigh the same, **except for one** which is heavier than all the others. The coins are otherwise indistinguishable. You may make no assumptions about how much heavier the heavy coin is. What is the minimum number of weighings needed to be certain of identifying the heavy coin?" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems/Egg Drop .ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Egg Drop .ipynb new file mode 100644 index 00000000..cbe1be74 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Egg Drop .ipynb @@ -0,0 +1,38 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Egg Drop \n", + "This is probably the most common brain teaser riddle out of the group, so really try to think algorithmically about this problem before looking at the solution!\n", + "## Problem Statement\n", + "\n", + "A tower has 100 floors. You've been given two eggs. The eggs are strong enough that they can be dropped from a particular floor in the tower without breaking. You've been tasked to find the highest floor an egg can be dropped without breaking, in as few drops as possible. If an egg is dropped from above its target floor it will break. If it is dropped from that floor or below, it will be intact and you can test drop the egg again on another floor.\n", + "\n", + "Show algorithmically how you would go about doing this in as few drops as possible. (Your answer should be a number of the fewest drops needed for testing 2 eggs on 100 floors)" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems/Hallway Lockers.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Hallway Lockers.ipynb new file mode 100644 index 00000000..402bfffd --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Hallway Lockers.ipynb @@ -0,0 +1,35 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Hallway Lockers\n", + "## Problem Statement\n", + "\n", + "You are in a hallway lined with 100 lockers. You start with one pass and open the lockers, so that the *opened* lockers are now with their doors opened out. You begin by closing **every second** locker. Then you go to close **every third** locker and **close it if it is open or open it if it’s closed** — we will refer to this as \"toggling\" the lockers. You continue toggling every nth locker on pass number n. After your hundredth pass of the hallway, in which you toggle only locker number 100, how many lockers are open?\n" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} 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 new file mode 100644 index 00000000..727614de --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Jugs of Water .ipynb @@ -0,0 +1,35 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Jugs of Water \n", + "## Problem Statement\n", + "\n", + "You have a five gallons jug and a three gallons jug, and an unlimited supply of water (but no measuring cups) How would you come up with exactly four gallons of water?" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems/Light Switches .ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Light Switches .ipynb new file mode 100644 index 00000000..b3b8995a --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Light Switches .ipynb @@ -0,0 +1,37 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Light Switches\n", + "## Problem Statement\n", + "\n", + "You are in a hallway next to three light switches, all of which are off. Each switch activates a different *incandescent* light bulb in the room at the end of the hall. You cannot see the lights from where the switches are. Your task is to determine which light corresponds to each switch. However, you may go into the room with the lights only once.\n", + "\n", + "**Note: This is a bit of \"trick\" question, so don't spend too much time on it. Although it is more on the \"fun\" side of brain teaser type questions.**\n" + ] + } + ], + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Riddles/Riddle Interview Problems/Riddle Interview Problems/Ropes Burning.ipynb b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Ropes Burning.ipynb new file mode 100644 index 00000000..c9f81f96 --- /dev/null +++ b/Riddles/Riddle Interview Problems/Riddle Interview Problems/Ropes Burning.ipynb @@ -0,0 +1,39 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Ropes Burning \n", + "## Problem Statement\n", + "\n", + "You have two ropes. Each takes exactly 60 minutes to burn.\n", + "\n", + "They are made of different material so even though they take the same amount of time to burn, they burn at separate rates. In addition, each rope burns inconsistently.\n", + "\n", + "How do you measure out exactly 45 minutes?" + ] + } + ], + "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.11" + } + }, + "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 -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 new file mode 100644 index 00000000..274f3ace --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Balanced Parentheses Check -checkpoint.ipynb @@ -0,0 +1,171 @@ +{ + "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": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[]')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[](){([[[]]])}')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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 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/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 new file mode 100644 index 00000000..d5c255f7 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Deque -checkpoint.ipynb @@ -0,0 +1,51 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Deque \n", + "\n", + "Finally, implement a Deque class! It should be able to do the following:\n", + "\n", + "* Check if its empty\n", + "* Add to both front and rear\n", + "* Remove from Front and Rear\n", + "* Check the Size" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Deque(object):\n", + " pass" + ] + } + ], + "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/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 new file mode 100644 index 00000000..907956a6 --- /dev/null +++ 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 @@ -0,0 +1,131 @@ +{ + "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/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 new file mode 100644 index 00000000..a5ac0019 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Queue-checkpoint.ipynb @@ -0,0 +1,51 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Queue\n", + "\n", + "It's very common to be asked to implement a Queue class! The class should be able to do the following:\n", + "\n", + "* Check if Queue is Empty\n", + "* Enqueue\n", + "* Dequeue\n", + "* Return the size of the Queue" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Queue(object):\n", + " pass" + ] + } + ], + "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/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 new file mode 100644 index 00000000..6dea3952 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/.ipynb_checkpoints/Implement a Stack -checkpoint.ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Stack \n", + "\n", + "A very common interview question is to begin by just implementing a Stack! Try your best to implement your own stack!\n", + "\n", + "It should have the methods:\n", + "\n", + "* Check if its empty\n", + "* Push a new item\n", + "* Pop an item\n", + "* Peek at the top item\n", + "* Return the size" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Stack(object):\n", + " \n", + " \n", + " # Fill out the Stack Methods here\n", + " pass" + ] + } + ], + "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/Balanced Parentheses Check .ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check .ipynb new file mode 100644 index 00000000..274f3ace --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Balanced Parentheses Check .ipynb @@ -0,0 +1,171 @@ +{ + "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": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[]')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "balance_check('[](){([[[]]])}')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "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": { + "collapsed": false + }, + "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 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/Implement a Deque .ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Deque .ipynb new file mode 100644 index 00000000..d5c255f7 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Deque .ipynb @@ -0,0 +1,51 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Deque \n", + "\n", + "Finally, implement a Deque class! It should be able to do the following:\n", + "\n", + "* Check if its empty\n", + "* Add to both front and rear\n", + "* Remove from Front and Rear\n", + "* Check the Size" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Deque(object):\n", + " pass" + ] + } + ], + "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/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 new file mode 100644 index 00000000..907956a6 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Queue -Using Two Stacks .ipynb @@ -0,0 +1,131 @@ +{ + "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/Implement a Queue.ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Queue.ipynb new file mode 100644 index 00000000..a5ac0019 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Queue.ipynb @@ -0,0 +1,51 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Queue\n", + "\n", + "It's very common to be asked to implement a Queue class! The class should be able to do the following:\n", + "\n", + "* Check if Queue is Empty\n", + "* Enqueue\n", + "* Dequeue\n", + "* Return the size of the Queue" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Queue(object):\n", + " pass" + ] + } + ], + "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/Implement a Stack .ipynb b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Stack .ipynb new file mode 100644 index 00000000..6dea3952 --- /dev/null +++ b/Stacks, Queues and Deques/Stacks, Queues, and Deques Interview Problems/Stacks, Queues, Deques Interview Questions/Implement a Stack .ipynb @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Implement a Stack \n", + "\n", + "A very common interview question is to begin by just implementing a Stack! Try your best to implement your own stack!\n", + "\n", + "It should have the methods:\n", + "\n", + "* Check if its empty\n", + "* Push a new item\n", + "* Pop an item\n", + "* Peek at the top item\n", + "* Return the size" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "class Stack(object):\n", + " \n", + " \n", + " # Fill out the Stack Methods here\n", + " pass" + ] + } + ], + "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 +}