Skip to content

Commit

Permalink
[feature] add problem
Browse files Browse the repository at this point in the history
  • Loading branch information
gitgik committed Dec 2, 2020
1 parent 5122447 commit 72af735
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions recursion/matrix_maximum_coins.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Problem \n",
"You are given a 2-d matrix where each cell represents number of coins in that cell. Assuming we start at matrix[0][0], and can only move right or down, find the maximum number of coins you can collect by the bottom right corner.\n",
"\n",
"For example, in this matrix\n",
"\n",
"```python\n",
"0 3 1 1\n",
"2 0 0 4\n",
"1 5 3 1\n",
"```\n",
"\n",
"The most we can collect is 0 + 2 + 1 + 5 + 3 + 1 = 12 coins."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def collect_coins(matrix, r=0, c=0, cache=None):\n",
" if cache is None:\n",
" cache = {}\n",
" \n",
" is_bottom = matrix[]\n",
" is_rightmost = matrix[-1][-1]\n",
" if (r, c) not in cache:\n",
" if cache[r][c]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 72af735

Please sign in to comment.