mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Fixed pull request changes
This commit is contained in:
parent
3370106d36
commit
e8de164d9d
|
@ -216,7 +216,7 @@ Challenges, solutions, and unit tests are presented in the form of **IPython/Jup
|
||||||
| Print all valid combinations of n-pairs of parentheses | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
| Print all valid combinations of n-pairs of parentheses | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
||||||
| Implement a paint fill function | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
| Implement a paint fill function | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
||||||
| Find all permutations to represent n cents, given 1, 5, 10, 25 cent coins | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
| Find all permutations to represent n cents, given 1, 5, 10, 25 cent coins | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
||||||
| Find the number of ways to represent n cents given k arbitrary cent coins | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change_ways/coinchange_ways_challenge.ipynb)│[Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change_ways/coinchange_ways_solution.ipynb) |
|
| Find the number of ways to represent n cents given an array of coins | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change_ways/coinchange_ways_challenge.ipynb)│[Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change_ways/coinchange_ways_solution.ipynb) |
|
||||||
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
"source": [
|
"source": [
|
||||||
"## Explanation\n",
|
"## Explanation\n",
|
||||||
"\n",
|
"\n",
|
||||||
"How many ways are there of making change for n, given k distinct coins? For example:\n",
|
"How many ways are there of making change for n, given an array of distinct coins? For example:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Input: n = 4, k = 2, coins = [1,2]\n",
|
"Input: n = 4, coins = [1, 2]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Output: 3. 1+1+1+1, 1+2+1, 2+2, would be the ways of making change.\n",
|
"Output: 3. 1+1+1+1, 1+2+1, 2+2, would be the ways of making change.\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -49,9 +49,9 @@
|
||||||
"source": [
|
"source": [
|
||||||
"## Test Cases\n",
|
"## Test Cases\n",
|
||||||
"\n",
|
"\n",
|
||||||
"* Input: n = 0, k = 2, coins = [1,2] -> Output: 0\n",
|
"* Input: n = 0, coins = [1, 2] -> Output: 0\n",
|
||||||
"* Input: n = 100, k = 3, coins = [1,2,3] -> Output: 884\n",
|
"* Input: n = 100, coins = [1, 2, 3] -> Output: 884\n",
|
||||||
"* Input: n = 1000, k = 100, coins = [1,2,3...99,100] -> Output: 15658181104580771094597751280645\n"
|
"* Input: n = 1000, coins = [1, 2, 3...99, 100] -> Output: 15658181104580771094597751280645\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def change_ways(n,k,coins):\n",
|
"def change_ways(n, coins):\n",
|
||||||
" # TODO: Implement me\n",
|
" # TODO: Implement me\n",
|
||||||
" return n"
|
" return n"
|
||||||
]
|
]
|
||||||
|
@ -115,9 +115,9 @@
|
||||||
"class Challenge(object):\n",
|
"class Challenge(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_coinchange_ways(self,solution):\n",
|
" def test_coinchange_ways(self,solution):\n",
|
||||||
" assert_equal(solution(0,2,[1,2]), 0)\n",
|
" assert_equal(solution(0, [1, 2]), 0)\n",
|
||||||
" assert_equal(solution(100,3,[1,2,3]), 884)\n",
|
" assert_equal(solution(100, [1, 2, 3]), 884)\n",
|
||||||
" assert_equal(solution(1000,100,range(1,101)), 15658181104580771094597751280645)\n",
|
" assert_equal(solution(1000, range(1, 101)), 15658181104580771094597751280645)\n",
|
||||||
" print('Success: test_coinchange_ways')\n",
|
" print('Success: test_coinchange_ways')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
"* We are essentially adding the coin we are iterating on to the # of ways of making arr[i].\n",
|
"* We are essentially adding the coin we are iterating on to the # of ways of making arr[i].\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Complexity:\n",
|
"Complexity:\n",
|
||||||
"* Time: O(mn)\n",
|
"* Time: O(mn); let the number of coins be m. We iterate from arr[coin] -> arr[n], or ~ n operations on each coin, hence n*m. \n",
|
||||||
"* Space: O(n)"
|
"* Space: O(n)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -73,10 +73,10 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def change_ways(n,k,coins):\n",
|
"def change_ways(n, coins):\n",
|
||||||
" arr = [1] + [0] * n\n",
|
" arr = [1] + [0] * n\n",
|
||||||
" for coin in coins:\n",
|
" for coin in coins:\n",
|
||||||
" for i in xrange(coin,n + 1):\n",
|
" for i in range(coin, n + 1):\n",
|
||||||
" arr[i] += arr[i - coin]\n",
|
" arr[i] += arr[i - coin]\n",
|
||||||
" return 0 if n == 0 else arr[n]"
|
" return 0 if n == 0 else arr[n]"
|
||||||
]
|
]
|
||||||
|
@ -112,9 +112,9 @@
|
||||||
"class Challenge(object):\n",
|
"class Challenge(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_coinchange_ways(self,solution):\n",
|
" def test_coinchange_ways(self,solution):\n",
|
||||||
" assert_equal(solution(0,2,[1,2]), 0)\n",
|
" assert_equal(solution(0, [1, 2]), 0)\n",
|
||||||
" assert_equal(solution(100,3,[1,2,3]), 884)\n",
|
" assert_equal(solution(100, [1, 2, 3]), 884)\n",
|
||||||
" assert_equal(solution(1000,100,range(1,101)), 15658181104580771094597751280645)\n",
|
" assert_equal(solution(1000, range(1, 101)), 15658181104580771094597751280645)\n",
|
||||||
" print('Success: test_coinchange_ways')\n",
|
" print('Success: test_coinchange_ways')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
|
@ -4,9 +4,9 @@ from nose.tools import assert_equal
|
||||||
class Challenge(object):
|
class Challenge(object):
|
||||||
|
|
||||||
def test_coinchange_ways(self,solution):
|
def test_coinchange_ways(self,solution):
|
||||||
assert_equal(solution(0,2,[1,2]), 0)
|
assert_equal(solution(0, [1, 2]), 0)
|
||||||
assert_equal(solution(100,3,[1,2,3]), 884)
|
assert_equal(solution(100, [1, 2, 3]), 884)
|
||||||
assert_equal(solution(1000,100,range(1,101)), 15658181104580771094597751280645)
|
assert_equal(solution(1000, range(1, 101)), 15658181104580771094597751280645)
|
||||||
print('Success: test_coinchange_ways')
|
print('Success: test_coinchange_ways')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user