Re: [algogeeks] DE Shaw written test

2012-08-07 Thread algo bard
The problem boils down to this: http://www.geeksforgeeks.org/archives/6463 On Tue, Aug 7, 2012 at 1:59 PM, manish patel wrote: > This is maximum sub-array problem. Nice explaination is given in CLRS - > "Introduction to algorithms " Pg 68, ch-4 3rd edition > > > On Tue, Aug 7, 2012 at 11:00 AM,

Re: [algogeeks] DE Shaw written test

2012-08-07 Thread manish patel
This is maximum sub-array problem. Nice explaination is given in CLRS - "Introduction to algorithms " Pg 68, ch-4 3rd edition On Tue, Aug 7, 2012 at 11:00 AM, Navin Gupta wrote: > @ashgoel :- Thanx for pointing it out, my earlier approach doesn't work. > Please check if this works. > We can appl

Re: [algogeeks] DE Shaw written test

2012-08-07 Thread Navin Gupta
@ashgoel :- Thanx for pointing it out, my earlier approach doesn't work. Please check if this works. We can apply this:- For every element, find the highest element to the right of it. For e.g: I/P:- 35 4015 35 10 20 Highest to Right:- 40 3535 20

Re: [algogeeks] DE Shaw written test

2012-08-06 Thread Ashish Goel
the only one scenario. > Other like random order profits and loss so need to decide min n max for a > interval. > > Here is no profit > 9 8 7 6 5 4 3 2 1 :(. > Sent from my Windows Phone > -- > From: Mukul Gupta > Sent: 08/05/2012 8:47 PM >

RE: [algogeeks] DE Shaw written test

2012-08-06 Thread umesh kewat
random order profits and loss so need to decide min n max for a interval. Here is no profit 9 8 7 6 5 4 3 2 1 :(. Sent from my Windows Phone -- From: Mukul Gupta Sent: 08/05/2012 8:47 PM To: algogeeks@googlegroups.com Subject: Re: [algogeeks] DE Shaw written test Thanks for

Re: [algogeeks] DE Shaw written test

2012-08-05 Thread Mukul Gupta
Thanks for pointing out the mistake.Though my code will correctly calculate the max_profit but I must keep track of the buying_day.I have made some modification in my code.Hope it works fine now. int min = a[0]; // initialized to first element int max_profit = 0; //when you buy and sell on same

Re: [algogeeks] DE Shaw written test

2012-08-05 Thread Arun Kindra
@harsha : yes, the problem is if u r finding only min and max value, it might happen that u sell the stock before buying. Ex- int a [ ] = { 5, 10, 4, 6, 7 }; the min value is 4 and max is 10 and 10 comes before 4, means u sell the stock before buying. and i think the sol given by mukul does the sa

Re: [algogeeks] DE Shaw written test

2012-08-05 Thread Mukul Gupta
This can be done in O(n) time complexity and O(1) space complexity using dynamic programming.Consider a situation in which I have been given an array of stock values for N days (in your case N=365) which looks like: int a [ ] = { 5, 10, 4, 6, 7 }; Now,use two variables min (which will keep track