fork download
  1. # your code goes here
  2.  
  3. x = [1, 5, 2, 4, 1]
  4. k = 3
  5. seen = set()
  6. found = False
  7.  
  8. for num in x:
  9. if (num + k) in seen or (num -k) in seen:
  10. print(f"Difference found: {num + k} - {num} = {k}")
  11. found = True
  12.  
  13. seen.add(num)
  14.  
  15. if not found:
  16. print("No difference found")
Success #stdin #stdout 0.06s 14076KB
stdin
Standard input is empty
stdout
Difference found: 5 - 2 = 3
Difference found: 7 - 4 = 3
Difference found: 4 - 1 = 3