-
Notifications
You must be signed in to change notification settings - Fork 2
feat(algorithms) non constructible change #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Non-Constructible Change | ||
|
|
||
| Given an array of positive integers representing the values of coins in your | ||
| possession, write a function that returns the minimum amount of change (the | ||
| minimum sum of money) that you cannot create. The given coins can have | ||
| any positive integer value and aren't necessarily unique (i.e., you can have | ||
| multiple coins of the same value). | ||
|
|
||
|
|
||
| Sample Input: | ||
|
|
||
| ```plain | ||
| coins = [5,7,1,1,2,3,22] | ||
| ``` | ||
|
|
||
| Sample output: | ||
|
|
||
| ```plain | ||
| 20 | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from typing import List | ||
|
|
||
|
|
||
| def non_constructible_change(coins: List[int]) -> int: | ||
| """ | ||
|
|
||
| """ | ||
| coins.sort() | ||
|
|
||
| current_change_created = 0 | ||
|
|
||
| for coin in coins: | ||
| if coin > current_change_created + 1: | ||
| return current_change_created + 1 | ||
| current_change_created += coin | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| return current_change_created + 1 | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||
| import unittest | ||||||
| from . import non_constructible_change | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use absolute import so tests work via discovery and when run as a script. The relative import breaks if this file is executed directly (your main block implies that use). Prefer an absolute import. -from . import non_constructible_change
+from algorithms.arrays.non_constructible_change import non_constructible_change📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
|
|
||||||
| class NonConstructibleChangeTestCase(unittest.TestCase): | ||||||
| def test_1(self): | ||||||
| """should return 20 for input of [5, 7, 1, 1, 2, 3, 22]""" | ||||||
| coins = [5, 7, 1, 1, 2, 3, 22] | ||||||
| expected = 20 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_2(self): | ||||||
| """should return 6 for input of [1, 1, 1, 1, 1]""" | ||||||
| coins = [1, 1, 1, 1, 1] | ||||||
| expected = 6 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_3(self): | ||||||
| """should return 55 for input of [1, 5, 1, 1, 1, 10, 15, 20, 100]""" | ||||||
| coins = [1, 5, 1, 1, 1, 10, 15, 20, 100] | ||||||
| expected = 55 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_4(self): | ||||||
| """should return 3 for input of [6, 4, 5, 1, 1, 8, 9]""" | ||||||
| coins = [6, 4, 5, 1, 1, 8, 9] | ||||||
| expected = 3 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_5(self): | ||||||
| """should return 1 for input of []""" | ||||||
| coins = [] | ||||||
| expected = 1 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_6(self): | ||||||
| """should return 1 for input of [87]""" | ||||||
| coins = [87] | ||||||
| expected = 1 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_7(self): | ||||||
| """should return 32 for input of [5, 6, 1, 1, 2, 3, 4, 9]""" | ||||||
| coins = [5, 6, 1, 1, 2, 3, 4, 9] | ||||||
| expected = 32 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_8(self): | ||||||
| """should return 19 for input of [5, 6, 1, 1, 2, 3, 43]""" | ||||||
| coins = [5, 6, 1, 1, 2, 3, 43] | ||||||
| expected = 19 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_9(self): | ||||||
| """should return 3 for input of [1, 1]""" | ||||||
| coins = [1, 1] | ||||||
| expected = 3 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_10(self): | ||||||
| """should return 1 for input of [2]""" | ||||||
| coins = [2] | ||||||
| expected = 1 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_11(self): | ||||||
| """should return 2 for input of [1]""" | ||||||
| coins = [1] | ||||||
| expected = 2 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_12(self): | ||||||
| """should return 87 for input of [109, 2000, 8765, 19, 18, 17, 16, 8, 1, 1, 2, 4]""" | ||||||
| coins = [109, 2000, 8765, 19, 18, 17, 16, 8, 1, 1, 2, 4] | ||||||
| expected = 87 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
| def test_13(self): | ||||||
| """should return 29 for input of [1, 2, 3, 4, 5, 6, 7]""" | ||||||
| coins = [1, 2, 3, 4, 5, 6, 7] | ||||||
| expected = 29 | ||||||
| actual = non_constructible_change(coins) | ||||||
| self.assertEqual(actual, expected) | ||||||
|
|
||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
| unittest.main() | ||||||
Uh oh!
There was an error while loading. Please reload this page.