aboutsummaryrefslogtreecommitdiff
path: root/challenge-283/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-283/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-283/paulo-custodio/python/ch-1.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-283/paulo-custodio/python/ch-1.py b/challenge-283/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..2cedb20d5d
--- /dev/null
+++ b/challenge-283/paulo-custodio/python/ch-1.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+
+# Challenge 283
+#
+# Task 1: Unique Number
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an array of integers, @ints, where every elements appears more
+# than once except one element.
+#
+# Write a script to find the one element that appears exactly one time.
+# Example 1
+#
+# Input: @ints = (3, 3, 1)
+# Output: 1
+#
+# Example 2
+#
+# Input: @ints = (3, 2, 4, 2, 4)
+# Output: 3
+#
+# Example 3
+#
+# Input: @ints = (1)
+# Output: 1
+#
+# Example 4
+#
+# Input: @ints = (4, 3, 1, 1, 1, 4)
+# Output: 3
+
+import sys
+
+ints = [int(x) for x in sys.argv[1:]]
+count = {}
+for x in ints:
+ if x in count:
+ count[x] += 1
+ else:
+ count[x] = 1
+unique = list(filter(lambda x:count[x]==1, ints))
+if len(unique) == 0:
+ print(-1)
+else:
+ print(unique[0])