We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
definit_cmp(mp,x,y):ifxnotinmp:mp[x]=xifynotinmp:mp[y]=ydefinit_cc(cc,x,y):ifxnotincc:cc[x]=1ifynotincc:cc[y]=1defget_parent(mp,x):whilemp[x]!=x:x=mp[x]returnx# Complete the maxCircle function below.defmaxCircle(queries):mp={}cc={}max_gp=0res=[]forqinqueries:init_cmp(mp,q[0],q[1])init_cc(cc,q[0],q[1])p1=get_parent(mp,q[0])p2=get_parent(mp,q[1])ifp1!=p2:ifcc[p1]>cc[p2]:mp[p2]=p1cc[p1]=cc[p1]+cc[p2]else:mp[p1]=p2cc[p2]=cc[p1]+cc[p2]max_gp=max(max_gp,max(cc[p1],cc[p2]))res.append(max_gp)returnres
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Friend Circle Queries
You are viewing a single comment's thread. Return to all comments →
Python 3 code: