aboutsummaryrefslogtreecommitdiff
path: root/challenge-056/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-056/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-056/paulo-custodio/python/ch-1.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-056/paulo-custodio/python/ch-1.py b/challenge-056/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..38a1c8f8b8
--- /dev/null
+++ b/challenge-056/paulo-custodio/python/ch-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+# Challenge 056
+#
+# TASK #1
+# Diff-K
+# You are given an array @N of positive integers (sorted) and another non
+# negative integer k.
+#
+# Write a script to find if there exists 2 indices i and j such that
+# A[i] - A[j] = k and i != j.
+#
+# It should print the pairs of indices, if any such pairs exist.
+#
+# Example:
+#
+# @N = (2, 7, 9)
+# $k = 2
+# Output : 2,1
+
+import sys
+
+k = int(sys.argv[1])
+n = [int(x) for x in sys.argv[2:]]
+
+for i in range(0, len(n)-1):
+ for j in range(i+1, len(n)):
+ if abs(n[i]-n[j]) == k:
+ print(str(i)+","+str(j))