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.
classBTree:def__init__(self,n):self.n=nself.data=[0]*(n+1)defquery(self,i):res=0whilei>0:res+=self.data[i]i-=i&-ireturnresdefupdate(self,i):whilei<=self.n:self.data[i]+=1i+=i&-ideflarrysArray(A):n=len(A)tree=BTree(max(A))swaps=0foriinrange(n):# subtract the number of elements <= A[i]-1 from our positionswaps+=i-tree.query(A[i]-1)tree.update(A[i])return"NO"if(swaps%2)else"YES"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Larry's Array
You are viewing a single comment's thread. Return to all comments →