### nikhacks's blog

By nikhacks, history, 5 months ago, ,

I have submitted this solution for This problem. I have done normal BFS traversal from both the ends. But I am getting TLe. What is wrong in my solution. Is it something like infinite loop. I am not able to figure it out.

• -3

By nikhacks, history, 5 months ago, ,

Question: Two arrays are given in sorted order and an index x is given. We need to do find a pair of indexes {i, j} such that A[i] + A[j] + A[x] = B[x]. All the 3 indexes should be different. I want to count the number of such pairs. How this can be done in linear time.

• 0

By nikhacks, history, 6 months ago, ,

I want to devise a data structure which should do these 2 queries in log(n) time

1 e : insert element e into the data structure

2 k find the number of elements strictly smaller than k in the data structure.

If I use multiset then I can use lower_bound to find the iterator but to convert it into index I need to use std::distance which runs in linear time. Like this

auto it = myMultiset.lower_bound(k); int numbeOfElements = distance(myMultiset.begin(), it);

How can I process the two queries in log(n) time

• -4

By nikhacks, 6 months ago, ,

An array is given containing n elements which might contain duplicates. How to find the total number of distinct subsets of this array. If we find the frequencies of all the elements, add 1 to them and then multiply all of them, we will get all the combinations of the set of frequency of all the elements in a subset. But how to account for order of elements.

Also once it is found now I want to find the number of distinct subsets if all the occurrences of particular element is removed from the array and hence not included in any subset. Since I want to find this for every element can this be done in O(1) for every element with the help of some preprocessing.