Adding to the question. See inline.
On Sunday, June 9, 2013 12:50:46 PM UTC+5:30, Monish Gupta wrote:
There are n Intervals. *1 = n = 1,000,000.* *Limits of interval are
within 64 bit signed int.* Given a set of m numbers, tell in how many
intervals does each number exists.
Example: 4
There are n Intervals. Given a set of m numbers, tell in how many intervals
does each number exists.
Example: 4 Intervals: [2,3] [3,4] [1,4] [3,10]. Numbers {2,4,11}
For 2 - 1 as 2 lies only in 1 interval [2,3]
For 4 - 3 as 4 lies in 3 intervals
For 11 - 0 as 11 lies in none of the given 4
Hi Nishant
As per the question, (priority queue) PQ is used to implement stack. With
PQ, you cannot do push and pop both in O(1). If you use heap tree(max heap
assuming you increase priority for upcoming pushed objects or min-heap
otherwise) for PQ, it will take O(log n) for each operation
You can use this logic to find number of bits set :-
int count = 0;
foreach(int x in array){
if(x 0)
count--; //for the sign bit will be counted below.
while(x){
x = x-1;
count++;
}
}
Thanks
Monish
On Sunday, May 12, 2013 1:05:31 AM UTC+5:30, rahul sharma wrote:
I was
You could also use Fly Weight pattern to implement this.
http://en.wikipedia.org/wiki/Flyweight_pattern
On Saturday, May 25, 2013 10:24:09 PM UTC+5:30, Nishant Pandey wrote:
In one of the interview it was asked, can some one suggest good DS for
this.
Thanks
--
You received this message