Created
July 28, 2025 14:58
-
-
Save inspirit941/f3535b21a5705c318c80b14bacc6ed5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python3 | |
| import math | |
| import os | |
| import random | |
| import re | |
| import sys | |
| # | |
| # Complete the 'pairs' function below. | |
| # | |
| # The function is expected to return an INTEGER. | |
| # The function accepts following parameters: | |
| # 1. INTEGER k | |
| # 2. INTEGER_ARRAY arr | |
| # | |
| def pairs(k, arr): | |
| # Write your code here | |
| candidates = set(arr) | |
| answer = 0 | |
| for data in arr: | |
| if data + k in candidates: | |
| answer += 1 | |
| return answer | |
| if __name__ == '__main__': | |
| fptr = open(os.environ['OUTPUT_PATH'], 'w') | |
| first_multiple_input = input().rstrip().split() | |
| n = int(first_multiple_input[0]) | |
| k = int(first_multiple_input[1]) | |
| arr = list(map(int, input().rstrip().split())) | |
| result = pairs(k, arr) | |
| fptr.write(str(result) + '\n') | |
| fptr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment