Re: [algogeeks] Re: Road crossing algorithm

2010-07-15 Thread Ashish kumar Jain
It is indeed an elegant interview question with respect to hiring for designing the systems.It was asked when I was interviewed for the final rounds of on-site interview at Google. On Thu, Jul 15, 2010 at 11:47 PM, Tech Id wrote: > Hi Ashish, > > Your algo does not have a chance for jump_back. >

[algogeeks] Time complexity................

2010-07-15 Thread UMESH KUMAR
Hello . How to decide insertion sort takes less cost of time for small input size. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send ema

Re: [algogeeks] Dynamic Programming Problem on Strings

2010-07-15 Thread Anil C R
that would be the Catlan number... Anil On Thu, Jul 15, 2010 at 11:41 PM, mohit ranjan wrote: > @Ajeet > * > Google "Dyck words*" > > > Mohit > > > > On Mon, Jul 12, 2010 at 1:43 PM, aejeet wrote: > >> A string can contain only the characters A and B. >> >> The string formation must follow the

[algogeeks] 0-1 knapsack problem: uniqueness of optimal solutions

2010-07-15 Thread Greg
Hello: This is a problem in theoretical computer science and algorithms. When solving the 0-1 knapsack problem using dynamic programming, how can you use the resulting table to determine whether the optimal solution is unique? The problem is the following: A thief is going to steal some items an

[algogeeks] The strong NO to circular lists argument

2010-07-15 Thread Jacko
http://groups.google.com/group/comp.lang.misc/browse_thread/thread/35967349de8446c1# -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email t

Re: [algogeeks] Dynamic Programming Problem on Strings

2010-07-15 Thread mohit ranjan
@Ajeet * Google "Dyck words*" Mohit On Mon, Jul 12, 2010 at 1:43 PM, aejeet wrote: > A string can contain only the characters A and B. > > The string formation must follow the following rules > 1. The number of occurrences of A and that of B must be equal in the > string > 2. For any prefix

[algogeeks] Re: graph

2010-07-15 Thread Gene
Construct the transitive closure of the graph. You can use Warshall's algorithm, which is O(v^3) in run time. If any row of the adjacency matrix is all 1's, the corresponding vertex can reach all others. You can ignore the diagonal element if you don't care whether vertices are reachable from th

[algogeeks] Re: Finding latitude and longitude

2010-07-15 Thread Gene
Think about it more carefully. If you are 1m south of the north pole, then walk pi meters east or west, your longitude changes by 180 degrees. At the equator it changes hardly at all. This is hard to do accurately and correctly over the whole earth. Google geographic coordinate transformations.

[algogeeks] Re: Road crossing algorithm

2010-07-15 Thread Tech Id
Hi Ashish, Your algo does not have a chance for jump_back. This may be required for certain cases, especially when multiple cars are running on one lane. My solution was for one car on one lane, hence car_times[i] gives the car in i-th lane will take to hit the path frog is trying to cross. It sh

Re: [algogeeks] Re: Road crossing algorithm

2010-07-15 Thread Ashish Goel
http://code.google.com/p/frogger-game/source/browse/trunk/ can it be interview question?? the frong will wait and this would vary at run time, the car_times is storing just one value, multiple cars can come in a lane so it should be hash map one thought: for each lane we know when the car would

[algogeeks] Re: Road crossing algorithm

2010-07-15 Thread Tech Id
An inefficient but working method is the brute force one. Do a recursive test for all the cases possible and if you find one which helps the frog cross the road, then that is it. Let int car_times[numLanes] store the time each car will take to reach the path where the frog is crossing the road. F

Re: [algogeeks] Re: sort in O(n) array which increases and then decreased and then increases...5,10,15,14,9,4,1,3,6,7,11,9,8,2

2010-07-15 Thread Ashish Goel
good one shifting array is the solution but i want to do it without shifting, is there a solution!!! Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Thu, Jul 15, 2010 at 4:26 AM, jalaj jaiswal wrote: > try merging this array > [{5,9,10},{3,6,7

Re: [algogeeks] Re: Finding latitude and longitude

2010-07-15 Thread siddharth srivastava
Hi On 15 July 2010 07:37, Tech Id wrote: > This seems to be asked in context of google maps. > I asked in terms of OSM. > > While drawing map at a particular zoom level, ratio of map-area-on- > screen and shown-latitudes/longitudes-area is known. > So, x meters can be converted to latitiude/lo

Re: [algogeeks] Stock prices.

2010-07-15 Thread Ashish Goel
technically i can sell first and buy later also so this solution doesnot consider shorts and long.. my algo would be return max(MaxStockGain(a,size), MaxStockGain(reverse(a,size),size)); can be done better..without reverse too :) lol Best Regards Ashish Goel "Think positive and find fuel in fai

[algogeeks] Re: Finding latitude and longitude

2010-07-15 Thread Tech Id
This seems to be asked in context of google maps. While drawing map at a particular zoom level, ratio of map-area-on- screen and shown-latitudes/longitudes-area is known. So, x meters can be converted to latitiude/longitude difference easily by this ratio. On Jul 15, 12:59 pm, siddharth srivasta

Re: [algogeeks] b tree:

2010-07-15 Thread naveen
sorry i didnt see it .. On Thu, Jul 15, 2010 at 4:18 AM, jalaj jaiswal wrote: > its b tree not binary tree > > > On Wed, Jul 14, 2010 at 10:45 AM, naveen wrote: > >> if I do two traversals of a tree inorder wise i can get it in O(n). >> Questions should be one traversal i think . Then we should

Re: [algogeeks] online movies streaming

2010-07-15 Thread ankur aggarwal
Hey moderator.. try 2 avoid these members... On Thu, Jul 15, 2010 at 1:01 AM, X +18 wrote: > http://bit.ly/aRDr4E > > Streaming entertainment network with lots of video clips. ... Use a > software called qvod player, you can watch the DVD movies online for free. > ... > > http://bit.ly/aRDr4E >

Re: [algogeeks] Google Interview Question

2010-07-15 Thread harit agarwal
@varun c should also be in the array -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. F

Re: [algogeeks] Google Interview Question

2010-07-15 Thread umesh kewat
Hi, suppose we have given n distinct numbers are a[n]. 1. sort them using quick or any other sort in O(nlogn) 2. use then int find(int *arr, int n) /* return largest number if fing it otheriwse retirn 0*/ { int i,j,k, temp; for(k=n-1; k>2;k--) { j = k-1 i=0; while(i!=j) { te

[algogeeks] Finding latitude and longitude

2010-07-15 Thread siddharth srivastava
Hi If I have a (latitude, langitude) as well as pixel positions of those locations, then how can (longitude, latitude) or pixel coordinates of a point x metres away can be found ? If this information is not enough, what else information might be required ? -- Siddharth Srivastava When you have

Re: [algogeeks] Stock prices.

2010-07-15 Thread jalaj jaiswal
int MaxStockGain(int arr[], int size) { if(size <= 0) return 0; int curMin = arr[0]; int MaxGain = 0; for(int i = 1; i < size; ++i) { if (arr[i] < curMin) { curMin = arr[i]; } int currGain = arr[i] - curMin; if(cur

Re: [algogeeks] Re: sort in O(n) array which increases and then decreased and then increases...5,10,15,14,9,4,1,3,6,7,11,9,8,2

2010-07-15 Thread jalaj jaiswal
try merging this array [{5,9,10},{3,6,7,9}]... On Wed, Jul 14, 2010 at 9:30 AM, Ashish Goel wrote: > > > int dstart = -1; > int dend = -1; > int istart=-1; int iend = -1; > bool decreasing = false; > for (int i=1;i { > if (a[i] >=a[i-1]) > { if (decreasing) > { > dend =i-1; istart=i

Re: [algogeeks] stack

2010-07-15 Thread Ashish kumar Jain
Another way in which this can be thought is in terms of Tower of Hanoi problem.Just introduce two more stacks of same size as input stack and get the sorted output as result. On Mon, Jun 14, 2010 at 9:18 AM, Anurag Sharma wrote: > Why not just pop all elements from stack ( O(n) ) and insert it i

Re: [algogeeks] b tree:

2010-07-15 Thread jalaj jaiswal
its b tree not binary tree On Wed, Jul 14, 2010 at 10:45 AM, naveen wrote: > if I do two traversals of a tree inorder wise i can get it in O(n). > Questions should be one traversal i think . Then we should use a tree where > nodes contain links to parents. > > > On Tue, Jul 13, 2010 at 6:58 PM,

Re: [algogeeks] Re: Difference b/w two elements in a array

2010-07-15 Thread jalaj jaiswal
> > I have one more question here , suppose we have some dynamic array >> ( of const size ) where insertions and removal is happening >> dynamically ---> >> you want the 2 elements from the array having least difference. Design >> a data structure for this. Less than O(n) solution appreciated. >> >

Re: [algogeeks] Re: AMAZON Interview Question

2010-07-15 Thread ankur aggarwal
@harit.. logic plz.. not the code.. On Wed, Jul 14, 2010 at 9:50 PM, harit agarwal wrote: > this is O(n) solution and using O(n) space... > > #include > #include > #include > using namespace std; > void leader_count(vector v,int *ar) > { > stack s; > int n=v.size(); > int i=n-1; > while(i>=0

Re: [algogeeks] Road crossing algorithm

2010-07-15 Thread Ashish kumar Jain
I think this will help: http://en.wikipedia.org/wiki/Frogger Consider the roads to be n-laned and of constant width with constant time traffic coming on each lane.For example,say after 1 minute,a car comes on each lane but in a arithmetic sequence and not all at same time.To make it more clear,