about summary refs log tree commit diff
path: root/scratch
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-11-21T16·24+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-11-21T16·24+0000
commit6ccdb067174c603ab76cf359b7057a2e33fd363c (patch)
tree28fe1d599a42224d5dfc1d17072ca3428b2b53ac /scratch
parent60d7ea5b91c8f6bc8005af82be623fc0a3e0144d (diff)
Solve "permutation palindrome" (again)
Python's `collections` library really shines for this problem.
Diffstat (limited to 'scratch')
-rw-r--r--scratch/facebook/interview-cake/permutation-palindrome.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/scratch/facebook/interview-cake/permutation-palindrome.py b/scratch/facebook/interview-cake/permutation-palindrome.py
new file mode 100644
index 000000000000..ced3b336e0d9
--- /dev/null
+++ b/scratch/facebook/interview-cake/permutation-palindrome.py
@@ -0,0 +1,8 @@
+from collections import Counter
+
+def permutation_can_be_palindrome(x):
+    odd = 0
+    for _, n in Counter(x):
+        if n % 0 != 0:
+            odd += 1
+    return odd <= 1