Mukul
BAN USERI am missing the point where is the extra space requirement for heap is coming from? As soon as you move the element to heap you do not have to keep it in the list so at any point in time total number of items stays the same.. if you move n items to heap then you have n less items on lists. So there is no extra space requirement...
 Mukul July 17, 2019Something is missing in the question. As there are many corner cases which will can not be satisfied with given conditions for e.g. At time 0 request to call setTimer(10, callback) and a second later another request comes in to setTimer(3, callback) . since 10 second timer is already running and its not allowed to be changed..there is no way to satisfy second request. At the time of firing the 10 second time there was no a priori knowledge of what is to come.
 Mukul June 16, 2019enter all orders in max heap sorted by costs. when need to query for costliest order check the timestamp of root node if less than X mins past then it is the costliest order if timestamp is more than X mins past then keep popping elements until timestamp is with x mins return the cost value of the top node.
 Mukul June 14, 2019Simply, maintain two HashMap. Parent Map and child map. In parent map keep a child count. In child map keep a parent info. When inserting new tuple check.
1. parent map already has more than 2 child count.
2. child already has same parent as in tuple
3. child already has a parent.
4. After all tuples are entered run through the parent table and count entries with 0 child if more than 1 flag error.
You are computing the algorithm BigO time incorrectly... it is not about how long it takes to generate n*(n1) pairs but the fact you can know that would be the answer in just O(n) time.. one can determine the max and min value of an array in O(n) time..so in O(n) time we would know that answer is all possible combinations
 Mukul September 06, 2016Good catch @joey.. here is another neat way to deal with this by creating a wrapper and still using @liuben10 method.
public static double wrapper(double value) {
if(value > 1.0 ) return findSquareRoot(value);
else return 1/findSquareRoot(1/value); // if value is <1 then compute 1/value first.
}

Mukul
September 05, 2016 int count (String s, int l, int consecutiveC, boolean bUsed, int n) {
if(l == n ) {
System.out.println(s);
return 1;
}
int c1 =0;
int c2 = 0;
int c3 =0;
//use 'a'
c1 = count(s+'a', l+1, 0, bUsed, n);
if(consecutiveC < 2) {
// use 'c'
c2 = count(s+'c', l+1, consecutiveC+1, bUsed, n );
}
if(!bUsed) {
// use 'b'
c3 = count(s+'b', l+1, 0, true, n);
}
return c1+c2+c3;
}

Mukul
September 04, 2016 Open Chat in New Window
Its not clear from your examples and description what is the real problem. How is the answer to your first example Yes, it should be No since you can't words "ab":2. Something is missing here or I am not following your question/description.
 Mukul July 20, 2019