Re: [algogeeks] Re: amazon ques :Online round

2011-08-27 Thread Piyush Grover
pardon 1 small mistake instead of if(i == 0 || i == n) return (lower, upper); it should be if(i == lower || i == upper) return (lower, upper); On Sat, Aug 27, 2011 at 8:31 PM, Piyush Grover wrote: > satisfy the point on lines, for point(x,y) to lie in between the two, the > f(x,y) value w

Re: [algogeeks] Re: amazon ques :Online round

2011-08-27 Thread Piyush Grover
satisfy the point on lines, for point(x,y) to lie in between the two, the f(x,y) value would have different sign. This can be done using the binary search approach. Here is the pseudo code: f(x,y) = Ax + By - C (x0, y0) initial Call: SearchLines(f, n/2, 0, n); SearchLines(f, i, lower, upper){ if(i

Re: [algogeeks] Re: amazon ques :Online round

2011-08-27 Thread Piyush Grover
I don't understand your point if y[i] < y[i+1] how come the slope is positive? It's just that the i'th line will lie under line i+1th line. On Sat, Aug 27, 2011 at 5:11 PM, monish001 wrote: > If I correctly understood the question, It says: > 1. 0<= x[i] <=1 for all i and for all x of line i. >

[algogeeks] Re: amazon ques :Online round

2011-08-27 Thread monish001
If I correctly understood the question, It says: 1. 0<= x[i] <=1 for all i and for all x of line i. 2. y[i] wrote: > You are given n no. of lines in form of Ax + By = C, basically you are given > A[i], b[i] and C[i] for line "i". > Lines are given in a way such that 0 <= x[i] <= 1 and y[i] < y[i+1]