mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-07 01:48:02 +00:00
Polish permutation challenge and solution
This commit is contained in:
@@ -41,6 +41,10 @@
|
||||
"* Is whitespace important?\n",
|
||||
" * Yes\n",
|
||||
"* Is this case sensitive? 'Nib', 'bin' is not a match?\n",
|
||||
" * Yes\n",
|
||||
"* Can we use additional data structures?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume this fits in memory?\n",
|
||||
" * Yes"
|
||||
]
|
||||
},
|
||||
@@ -50,6 +54,7 @@
|
||||
"source": [
|
||||
"## Test Cases\n",
|
||||
"\n",
|
||||
"* One or more None inputs -> False\n",
|
||||
"* One or more empty strings -> False\n",
|
||||
"* 'Nib', 'bin' -> False\n",
|
||||
"* 'act', 'cat' -> True\n",
|
||||
@@ -91,6 +96,8 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def permutations(str1, str2):\n",
|
||||
" if str1 is None or str2 is None:\n",
|
||||
" return False\n",
|
||||
" return sorted(str1) == sorted(str2)"
|
||||
]
|
||||
},
|
||||
@@ -141,6 +148,8 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"def permutations_alt(str1, str2):\n",
|
||||
" if str1 is None or str2 is None:\n",
|
||||
" return False\n",
|
||||
" if len(str1) != len(str2):\n",
|
||||
" return False\n",
|
||||
" unique_counts1 = defaultdict(int)\n",
|
||||
@@ -182,6 +191,7 @@
|
||||
"class TestPermutation(object):\n",
|
||||
"\n",
|
||||
" def test_permutation(self, func):\n",
|
||||
" assert_equal(func(None, 'foo'), False)\n",
|
||||
" assert_equal(func('', 'foo'), False)\n",
|
||||
" assert_equal(func('Nib', 'bin'), False)\n",
|
||||
" assert_equal(func('act', 'cat'), True)\n",
|
||||
|
||||
Reference in New Issue
Block a user