Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

intersection of 3 array in O(n) python

def intersection(A, B, C):
    '''
    Intersection of 3 array in O(n).
    '''
    i = j = k = 0
    len1 = len(A)
    len2 = len(B)
    len3 = len(C)
	
    while (i < len1 and j < len2 and k< len3):
        
        if (A[i] == B[j] and B[j] == C[k]):
            print(A[i])
            i += 1
            j += 1
            k += 1
        elif A[i] < B[j]:
            i += 1
        elif B[j] < C[k]:
            j += 1
        else:
            k += 1
Comment

PREVIOUS NEXT
Code Example
Python :: py var to the power of 
Python :: python mouse listener 
Python :: combine column in csv python pandas 
Python :: gunicorn django static files 
Python :: Add New Column to Pandas from Dictionary 
Python :: automatic regex generator python 
Python :: python ip address increment 
Python :: pairwise combinations groupby 
Python :: import in python 
Python :: Python Import all names 
Python :: python code to demonstrate inheritance with animal class 
Python :: python manual elif 
Python :: how to combine two lists in one python 
Python :: splitting on basis of regex python 
Python :: show only integer values matplotlib 
Python :: select inverse with conditions pandas 
Python :: dataframe concatenate 
Python :: stack widgets in tkinter 
Python :: tar dataset 
Python :: pandas assign value to row based on condition 
Python :: class python __call__ 
Python :: mechanize python #3 
Python :: python get image RGB data from URL 
Python :: reverse a string or number in python 
Python :: subprocess the system cannot find the file specifie 
Python :: print 
Python :: python set to none 
Python :: how to call a class from another class python? 
Python :: update matplotlib params 
Python :: activate venv environment 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =