Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Pairs with Specific Difference

function findPairsWithGivenDifference(arr, k):
    # since we don't allow duplicates, no pair can satisfy x - 0 = y
    if k == 0:
        return []
        
    map = {}
    answer = []
    
    for (x in arr):
        map[x - k] = x
    
    for (y in arr):
        if y in map:
            answer.push([map[y], y]) 

    return answer
Comment

PREVIOUS NEXT
Code Example
Python :: typecasting python 
Python :: how to print second largest number in python 
Python :: exponent function in python 
Python :: python calculator 
Python :: pandas df number of columns 
Python :: set intersection 
Python :: scrapy with selenium 
Python :: run pyinstaller from python 
Python :: convert date to string in python 
Python :: random forest algorithm 
Python :: what is xarray 
Python :: python json 
Python :: models django 
Python :: merge sort in python 
Python :: windows task scheduler python script 
Python :: argparse one argument or without argument 
Python :: Ignoring invalid distribution -ip (c:python310libsite-packages) 
Python :: remove item in dict 
Python :: self keyword in python 
Python :: @property python 
Python :: cudart64_110.dll not found 
Python :: add column to dataframe pandas 
Python :: logistic regression sklearn 
Python :: tuple python 
Python :: setup vs code for python 
Python :: indefinite loops 
Python :: tkinter hide legend 
Python :: convert from R to python 
Python :: output multiple LaTex equations in one cell in Google Colab 
Python :: analyser.polarity_scores get only positive 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =