Today we are going to share a Python program to find a pair with the given difference. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a Python program to find a pair with the given difference.
Copy the below python program and execute it with the help of python compiler.
size = len(arr)
# Initialize positions of two elements
i,j = 0,1
# Search for a pair
while i < size and j < size:
if i != j and arr[j]-arr[i] == n:
print "Pair found (",arr[i],",",arr[j],")"
elif arr[j] - arr[i] < n:
print "No pair found"
arr = [1, 8, 30, 40, 100]
n = 60
Pair Found: (40, 100)
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.