Re: [algogeeks] Re: spy in the city

2010-12-21 Thread janak
O(N) if everybody knows everybody. O(N^2) if there is no such condition. (i.e. Ask for each person to everybody.) On Mon, Dec 20, 2010 at 9:43 PM, Bhavesh Chauhan chauhan.bhave...@gmail.com wrote: Every question can eliminate 1 person so you can identify the spy in N-1 questions. Bhavesh

Re: [algogeeks] Amazon Interview

2010-09-23 Thread janak
http://en.wikipedia.org/wiki/Run-length_encoding On Wed, Sep 15, 2010 at 5:51 PM, bittu shashank7andr...@gmail.com wrote: A file is given with many 0s stored in continuous way , store it in another file such that when you store try saving the space by using minimum amount of space. When you

Re: [algogeeks] Re: algorithm

2010-07-28 Thread janak
How about keeping heap? Have two heaps 1. max heap and 2. min heap keep them equal size all the time and shift top element from one to other when required... On Wed, Jul 28, 2010 at 7:46 AM, Gene gene.ress...@gmail.com wrote: I think you have confused the statement of this problem.  The (in

Re: [algogeeks] Re: Largest even length palindrome in a string!!

2010-06-06 Thread janak chandarana
Suffix tree is obviously there but 1. It requires more lots of space. Just draw a suffix tree and you will know. 2. Pre-processing takes time. We cant ignore this time because its proportional to N. There is one linear solution described here:

Re: [algogeeks] Best Data Structure for this?

2010-06-06 Thread janak chandarana
Use hash table with customer ID as key. There can be three components in value: 1. num_days 2. pages 3. flag For each line, calculate hash, find value for given key. Increment appropriate values (i.e. pages or num_days). If num_days 1 pages 1, add this customer to result array, mark this

Re: [algogeeks] Re: Find Max Number of Elephants

2010-06-06 Thread janak
1. have an array of N years. starting with first year and ending at last year. O(N) space here. initialise all elements to zero. 2. Take array of E and birthyear first. Whenever you encounter new birthyear, do array[year]++. 3. Take array of E and deathyear now. Whenever you encounter new

Re: [algogeeks] Find the number with maximum frequency in an array. Better than O(nlogn + n) time complexity

2010-06-01 Thread janak chandarana
On Mon, May 31, 2010 at 10:01 PM, souravsain souravs...@gmail.com wrote: Hi All This is my first post to this community and so am exited. The problem is to find the no. that has maximum frequency in an array (size n) of integers. The approach to use a hash table, itereate through array

Re: [algogeeks] question

2010-05-21 Thread janak chandarana
step 1: Sort array in place. Lets call it A. (N log N) step 2: Create two additional copies of array, lets call them B and C. (this is just for explanation, we can operate on same array A). step 3: Take first element from array A. lets say its value is X. Find pair from B and C whose sum is