[algogeeks] Re: Google Interview Question: In how many intervals does a number exists

2013-06-11 Thread Monish Gupta
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

[algogeeks] Google Interview Question: In how many intervals does a number exists

2013-06-09 Thread Monish Gupta
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

Re: [algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)

2013-05-27 Thread Monish Gupta
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

[algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-27 Thread Monish Gupta
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

[algogeeks] Re: What data structures will you use to implement a text editor. Size of editor can be changed and you also need to save the styling information for all the text like italic, bold etc.EO

2013-05-27 Thread Monish Gupta
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