Re: [algogeeks] Re: Amazon ques

2012-01-27 Thread Sourabh Singh
@all plz.. tell if this thing would work.. assume 2 in place of every 0 in array. ie 1 1 0 0 0 1 0 1 be 1 1 2 2 2 1 2 1 then find max sub array wid sum length/2 * 3. this can be done in O(n) but worst case would still be O(n lgn) . On 1/26/12, Sanjay Rajpal sanjay.raj...@live.in wrote: +1

Re: [algogeeks] Re: Amazon ques

2012-01-26 Thread algoist
Consider 2 temp arrays, B and C Where B gets updated for every find of 0 and C for every find of 1 i.e if(a[i]==0) b[i]+=b[i-1]+1; c[i]=c[i-1]; i.e if(a[i]==1) c[i]+=c[i-1]+1; b[i]=b[i-1]; if(c[i]==b[i]) update max. return max. This is O(N) algo. Is it right or i

Re: [algogeeks] Re: Amazon ques

2012-01-26 Thread Ashish Goel
replace all 0s by -1 keep additional array to get the sumHere at every position of all -1s and 1s. say you got 0 1 0 1 0 0 0 0 1 1 1 1 0 -1 1 -1 1 -1 -1 -1 -1 1 1 1 1 -1 sum -1 0 -1 0 -1 -2 -3 -4 -3 -2 -1 0 -1 all equal numbers in sum shows equal zeros and 1s between then

Re: [algogeeks] Re: Amazon ques

2012-01-26 Thread Sanjay Rajpal
+1 * Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India Contact: +91-8053566286 * On Thu, Jan 26, 2012 at 6:28 PM, Ashish Goel ashg...@gmail.com wrote: replace all 0s by -1 keep additional array

Re: [algogeeks] Re: Amazon ques

2012-01-22 Thread praveen raj
Answer is already given in group search it... PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send

Re: [algogeeks] Re: Amazon ques

2012-01-21 Thread gaurav arora
yeah...u r right -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options,

Re: [algogeeks] Re: amazon ques

2011-12-29 Thread praveen raj
IT will grt help for me... if u all tell me.. mapstring,int m; m[topcoder]=2 My question is this: Is 2 is an key value??or index value of hash table...??... kindly explain how actual mapping is done... in hash table...plz... PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING On Tue, Dec 27,

Re: [algogeeks] Re: amazon ques

2011-12-29 Thread pankaj agarwal
same question as above with one more task is given 4) FindAnyElement() which will return any element present in that structure with O(1). for given all 4 task Please suggest which Data Structure is better now...? Best Regards, Pankaj Agarwal -- You received this message because you are

Re: [algogeeks] Re: amazon ques

2011-12-27 Thread Jagannath Prasad Das
@shashank and @samm: Is the deletion and searching is o(1). I doubt On Sat, Oct 1, 2011 at 6:30 PM, SAMM somnath.nit...@gmail.com wrote: Yaa it will work , but in case of deletion don't u think array will not as efficient as linked list becoz array is Static we need to define the memory b4

[algogeeks] Re: Amazon Ques Suggest Algo

2011-10-22 Thread vasanthi emani
nice idea.. On Oct 20, 11:04 am, SUMANTH M sumanth.n...@gmail.com wrote: - Take another sum array which contains sums of original array at each index, here sum[0] = a[0]; sum[1] = a[0] + a[1] ;...sum[i]=a[0]+a[1]+...a[i]; - Traverse the sum array and search for duplicates.   ex: a[] =

[algogeeks] Re: Amazon Ques Suggest Algo

2011-10-20 Thread Navneet
+1 for Sumanth's solution. On Oct 20, 12:03 pm, anshu mishra anshumishra6...@gmail.com wrote: index  =  0 1 2  3  4 5  6 ar       =  0 1 2 -4 -3 6 -3 sumar =  0 1 3 -1 -4 2 -1 first index where we get the number which has already appeared in sumar will be the last index of sub array whose

[algogeeks] Re: amazon ques

2011-10-01 Thread SAMMM
The hash table would be used by separate chaining method not open addressing because it may not find the correct entry efficiently in the hash table . In case of open addresssing the value gets entered in the first available entry after collision. In case of insertion :- (I have considered only

Re: [algogeeks] Re: amazon ques

2011-10-01 Thread shiva@Algo
Dont know how to delete (how adress will be known of the node? On Sat, Oct 1, 2011 at 12:27 PM, SAMMM somnath.nit...@gmail.com wrote: The hash table would be used by separate chaining method not open addressing because it may not find the correct entry efficiently in the hash table . In case

[algogeeks] Re: amazon ques

2011-10-01 Thread WgpShashank
@All Why don't try with combination of* hash-table Array* , It Will Work , try it out :P Thanks Shashank Mani CSE, BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Re: amazon ques

2011-10-01 Thread SAMM
Yaa it will work , but in case of deletion don't u think array will not as efficient as linked list becoz array is Static we need to define the memory b4 hand.. On 10/1/11, WgpShashank shashank7andr...@gmail.com wrote: @All Why don't try with combination of* hash-table Array* , It Will Work ,

Re: [algogeeks] Re: Amazon ques

2011-09-14 Thread surender sanke
however maximum subarray can be found in O(n) just needs to get maximum difference in entries of each A[i] [-2]-[5] [-1]-[0, 2, 4, 6] maxdiff[-1] = 6-0 [0]-[-1, 1, 3, 7] maxdiff[0] = 7-(-1) [1]-[8, 10] maxdiff[1] = 10-8 [2]-[9] max(maxdiff[i]) = 8 surender On Sun, Sep 11, 2011 at

[algogeeks] Re: Amazon ques

2011-09-11 Thread Brijesh
This is the fastest way I can think of to do this, and it is linear to the number of intervals there are. Let L be your original list of numbers and A be a hash of empty arrays where initially A[0] = [0] sum = 0 for i in 0..n if L[i] == 0: sum-- A[sum].push(i) elif L[i] == 1:

Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Kunal Patil
@Brijesh: +1 On Sun, Sep 11, 2011 at 2:14 PM, Brijesh brijeshupadhyay...@gmail.comwrote: This is the fastest way I can think of to do this, and it is linear to the number of intervals there are. Let L be your original list of numbers and A be a hash of empty arrays where initially A[0] =

Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Ankur Garg
This solution is not in O(n) time :( Unfortunately interviewer wants O(n) . On Sun, Sep 11, 2011 at 4:01 PM, Kunal Patil kp101...@gmail.com wrote: @Brijesh: +1 On Sun, Sep 11, 2011 at 2:14 PM, Brijesh brijeshupadhyay...@gmail.comwrote: This is the fastest way I can think of to do this,

Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Kunal Patil
As the author correctly mentions it: Building the array is O(n) , but printing these intervals must be done in linear time to the number of intervals. Assuming n means number of elements in the original array There are O(n^2) possible intervals, how can you print them in O(n) ??? On Sun, Sep 11,

Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Ankur Garg
Yeah :( U r right dude ...I dont think O(n) solution can exist for this problem On Sun, Sep 11, 2011 at 4:27 PM, Kunal Patil kp101...@gmail.com wrote: As the author correctly mentions it: Building the array is O(n) , but printing these intervals must be done in linear time to the number of

[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]y[i+1] means lines have positive slope If line i is f(x,y): A[i]x + B[i]y -C[i], Use the following concept: 1. Find 1 line closest to the given point such that f(x,y) is of same sign for both

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 monish.gup...@gmail.com wrote: If I correctly understood the question, It says: 1. 0= x[i] =1 for all i and for

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){

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 piyush4u.iit...@gmail.comwrote: satisfy the point on lines, for point(x,y) to lie in between the

[algogeeks] Re: Amazon Ques

2011-08-22 Thread vikas
why to bother this much...? just count the elements when popping and output the middle one . while(!s.empty()){ e= s.pop() count++ q.enq(e); } count = 2; while(count){ e = q.deq(); s.push(e); count --; } output s.top() while(!q.empty()){ e = q.deq(); s.push(e); } On Aug 22, 4:27 pm, Shravan

Re: [algogeeks] Re: Amazon Ques

2011-08-22 Thread shady
i wish u had read the question... it is simple.. push to new stack and then pop back... number of elements count need to be there On Mon, Aug 22, 2011 at 7:44 PM, muthu raj muthura...@gmail.com wrote: No need to count the number of nodes. Since its implemented as a linked list traverse the

Re: [algogeeks] Re: Amazon Ques

2011-08-22 Thread muthu raj
No need to count the number of nodes. Since its implemented as a linked list traverse the list with two two pointers one incremented one node next and other incremented two nodes next simultaneously. void delete_MiddleStack(node **h) { if(*h==NULL) return; node *p,*q; p=*h;

Re: [algogeeks] Re: Amazon Ques

2011-08-22 Thread sukran dhawan
count is required since its not implemented as LL On Mon, Aug 22, 2011 at 7:47 PM, shady sinv...@gmail.com wrote: i wish u had read the question... it is simple.. push to new stack and then pop back... number of elements count need to be there On Mon, Aug 22, 2011 at 7:44 PM, muthu raj

Re: [algogeeks] Re: Amazon Ques

2011-08-22 Thread muthu raj
Sorry i dint read the question properly :) *Muthuraj R IV th Year , ISE PESIT , Bangalore* On Mon, Aug 22, 2011 at 7:24 AM, sukran dhawan sukrandha...@gmail.comwrote: count is required since its not implemented as LL On Mon, Aug 22, 2011 at 7:47 PM, shady sinv...@gmail.com wrote: i wish

Re: [algogeeks] Re: Amazon Ques

2011-08-22 Thread *$*
Hi, How about the following approach. lets take stack is stack1. lets take 2 pointers , p1 and p2 for every pop , keep increment p1 , so that p1 will point to latest pop'ed out element. increment p2 for every odd count of pop's... increment p2 , for 1 , 3 , 5 , pop'ings etc.. so at the end , p2

Re: [algogeeks] Re: Amazon Ques

2011-08-22 Thread Ashima .
Since its not a Linked list, so get middle value from top pop till middle element and push elements in a new stack. again push the elemetns back to original stack,except for the middle element. Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Mon, Aug 22, 2011 at 8:49

[algogeeks] Re: Amazon ques

2011-07-20 Thread siva viknesh
gn array - say a hav extra array - say b - initialise all values to zero ques 1:for(i=1;i=n;i++) { b[a[i]]++; } On Jul 20, 12:07 pm, siva viknesh sivavikne...@gmail.com wrote: 1.Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except

Re: [algogeeks] Re: Amazon ques

2011-07-20 Thread Shubham Maheshwari
let A:: ((n(n+1)/2) - sum) let B:: ((n(n+1)(2n+1)/6) - (sum of squares of elements)) then missing number = ((B/A) + A)/2; complexity O(n). space complexity O(1). On Wed, Jul 20, 2011 at 12:47 PM, saurabh singh saurab...@gmail.com wrote: Q1 can be solved using some simple maths:)

Re: [algogeeks] Re: Amazon ques

2011-07-20 Thread saurabh singh
Q2 o(1) space o(n) sol. traverse through the array. do -1*a[abs(a[i])-1] if a[abs(a[i])-1) +ve else do nothing traverse again to check for the indexes with +ve values. On Wed, Jul 20, 2011 at 1:01 PM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: let A:: ((n(n+1)/2) - sum) let B::

Re: [algogeeks] Re: Amazon ques

2011-07-20 Thread JIƬΣN BAJIYA
simple one!! . all the missing nos which r not present b/w 1 to n will be printed!! TC O(n) #include stdio.h #define size 1 int main() { int i, j, n; scanf(%d, n); int a[n + 1] ; int b[n + 1] ; a[0] = 0; b[0] = 0; for (i = 1; i =

Re: [algogeeks] Re: Amazon ques

2011-07-20 Thread saurabh singh
space o(n) toomine takes o(1) space On Wed, Jul 20, 2011 at 3:50 PM, JIƬΣN BAJIYA j.s.baj...@gmail.com wrote: simple one!! . all the missing nos which r not present b/w 1 to n will be printed!! TC O(n) #include stdio.h #define size 1 int main() { int i, j, n;

[algogeeks] Re: Amazon ques

2011-07-20 Thread rkumar
I doubt if it would work on the following example : size of array is 10, 5 and 7 are missing numbers {1,2,3,4,6,6,6,8,9,10}; On Jul 20, 12:31 pm, Shubham Maheshwari shubham.veloc...@gmail.com wrote: let A:: ((n(n+1)/2) - sum) let B:: ((n(n+1)(2n+1)/6) - (sum of squares of elements)) then

[algogeeks] Re: Amazon ques

2011-07-20 Thread rkumar
I doubt if it would work on the following example : size of array is 10, 5 and 7 are missing numbers {1,2,3,4,6,6,6,8,9,10}; On Jul 20, 1:04 pm, Shubham Maheshwari shubham.veloc...@gmail.com wrote: @saurabh. kindly use a lil bit of indentation ... ur algo is illegible. On Wed, Jul