"""
You are given three arrays of integers a, b, and c. 
Your task is to find the longest contiguous subarray
of a containing only elements that appear in b but do not appear in c.

Given,
a=[2, 1, 7, 1, 1, 5, 3, 5, 2, 1, 1, 1]
b=[1, 3, 5]
c=[2, 3]

Return this longest subarray.
{[1,1,1] or [1,1,5]}
If there is more than one longest subarray satisfying these conditions, 
return any of these possible subarrays.
"""

a=[2, 1, 7, 1, 1, 5, 3, 5, 2, 1, 1, 1]
b=[1, 3, 5]
c=[2, 3]
s=set(b).difference(set(c))
temp=[]
ans=[]
try:
    for i in a:
        if(i in s):
            temp.append(i)
        else:
            if(len(temp)!=0):
                ans.append(temp)
                temp=[]            
    if(len(temp)!=0):
        ans.append(temp)
        temp=[]
    ans.sort(key=len)
    print(ans[-1])
except:
    print("[]")

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: