Skip to content

Commit b31c9b6

Browse files
committed
more mocks
1 parent f3b9df8 commit b31c9b6

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions - SOLUTIONS/.ipynb_checkpoints/On-Site Question 2 - SOLUTION-checkpoint.ipynb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,68 @@
1414
"\n",
1515
"** Write out your work on paper/pencil, then see if you can code up your solution **"
1616
]
17+
},
18+
{
19+
"cell_type": "markdown",
20+
"metadata": {},
21+
"source": [
22+
"## Solution\n",
23+
"\n",
24+
"This is a classic interview problem, so classic that you've already seen it when we discussed memoization and recursion! Refer to that lecture to see the full explanation! Here it is duplicated below:"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 1,
30+
"metadata": {
31+
"collapsed": true
32+
},
33+
"outputs": [],
34+
"source": [
35+
"def rec_coin_dynam(target,coins,known_results):\n",
36+
" '''\n",
37+
" INPUT: This funciton takes in a target amount and a list of possible coins to use.\n",
38+
" It also takes a third parameter, known_results, indicating previously calculated results.\n",
39+
" The known_results parameter shoud be started with [0] * (target+1)\n",
40+
" \n",
41+
" OUTPUT: Minimum number of coins needed to make the target.\n",
42+
" '''\n",
43+
" \n",
44+
" # Default output to target\n",
45+
" min_coins = target\n",
46+
" \n",
47+
" # Base Case\n",
48+
" if target in coins:\n",
49+
" known_results[target] = 1\n",
50+
" return 1\n",
51+
" \n",
52+
" # Return a known result if it happens to be greater than 1\n",
53+
" elif known_results[target] > 0:\n",
54+
" return known_results[target]\n",
55+
" \n",
56+
" else:\n",
57+
" # for every coin value that is <= than target\n",
58+
" for i in [c for c in coins if c <= target]:\n",
59+
" \n",
60+
" # Recursive call, note how we include the known results!\n",
61+
" num_coins = 1 + rec_coin_dynam(target-i,coins,known_results)\n",
62+
" \n",
63+
" # Reset Minimum if we have a new minimum\n",
64+
" if num_coins < min_coins:\n",
65+
" min_coins = num_coins\n",
66+
" \n",
67+
" # Reset the known result\n",
68+
" known_results[target] = min_coins\n",
69+
" \n",
70+
" return min_coins"
71+
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"# Good Job!"
78+
]
1779
}
1880
],
1981
"metadata": {

Mock Interviews/Ride Share Start-Up Company/Ride Share Company - Interview Questions - SOLUTIONS/On-Site Question 2 - SOLUTION.ipynb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,68 @@
1414
"\n",
1515
"** Write out your work on paper/pencil, then see if you can code up your solution **"
1616
]
17+
},
18+
{
19+
"cell_type": "markdown",
20+
"metadata": {},
21+
"source": [
22+
"## Solution\n",
23+
"\n",
24+
"This is a classic interview problem, so classic that you've already seen it when we discussed memoization and recursion! Refer to that lecture to see the full explanation! Here it is duplicated below:"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 1,
30+
"metadata": {
31+
"collapsed": true
32+
},
33+
"outputs": [],
34+
"source": [
35+
"def rec_coin_dynam(target,coins,known_results):\n",
36+
" '''\n",
37+
" INPUT: This funciton takes in a target amount and a list of possible coins to use.\n",
38+
" It also takes a third parameter, known_results, indicating previously calculated results.\n",
39+
" The known_results parameter shoud be started with [0] * (target+1)\n",
40+
" \n",
41+
" OUTPUT: Minimum number of coins needed to make the target.\n",
42+
" '''\n",
43+
" \n",
44+
" # Default output to target\n",
45+
" min_coins = target\n",
46+
" \n",
47+
" # Base Case\n",
48+
" if target in coins:\n",
49+
" known_results[target] = 1\n",
50+
" return 1\n",
51+
" \n",
52+
" # Return a known result if it happens to be greater than 1\n",
53+
" elif known_results[target] > 0:\n",
54+
" return known_results[target]\n",
55+
" \n",
56+
" else:\n",
57+
" # for every coin value that is <= than target\n",
58+
" for i in [c for c in coins if c <= target]:\n",
59+
" \n",
60+
" # Recursive call, note how we include the known results!\n",
61+
" num_coins = 1 + rec_coin_dynam(target-i,coins,known_results)\n",
62+
" \n",
63+
" # Reset Minimum if we have a new minimum\n",
64+
" if num_coins < min_coins:\n",
65+
" min_coins = num_coins\n",
66+
" \n",
67+
" # Reset the known result\n",
68+
" known_results[target] = min_coins\n",
69+
" \n",
70+
" return min_coins"
71+
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"# Good Job!"
78+
]
1779
}
1880
],
1981
"metadata": {

Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/.ipynb_checkpoints/Recursion Problem 4 - Coin Change - SOLUTION-checkpoint.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
"name": "python",
301301
"nbconvert_exporter": "python",
302302
"pygments_lexer": "ipython2",
303-
"version": "2.7.10"
303+
"version": "2.7.11"
304304
}
305305
},
306306
"nbformat": 4,

Recursion/Recursion Interview Problems/Recursion Problems - SOLUTIONS/Recursion Problem 4 - Coin Change - SOLUTION.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
"name": "python",
301301
"nbconvert_exporter": "python",
302302
"pygments_lexer": "ipython2",
303-
"version": "2.7.10"
303+
"version": "2.7.11"
304304
}
305305
},
306306
"nbformat": 4,

0 commit comments

Comments
 (0)