Finding MEX of a changing set

I am trying to create a method add that adds elements x to the set one by one and returns MEX (=minimum non-negative number not in the set) of the list at each point. class Mex: def __init__(self): self.mex = set() def add(self, x): self.mex.add(x) mex = 0 while mex in self.mex: mex += 1… Read More Finding MEX of a changing set

Find triplets from an array such that i<j<k, A[i]<A[j]<A[k] and B[i]+B[j]+B[k] is maximum

There are two arrays A and B. I need to find sum of triplet in B with three conditions :- i<j<k (where i j and k are indexes) A[i]<A[j]<A[k] B[i]+B[j]+B[k] is maximum I have tried this question but I can not find a way to optimize it. The time complexity that I am getting is… Read More Find triplets from an array such that i<j<k, A[i]<A[j]<A[k] and B[i]+B[j]+B[k] is maximum