Re: [algogeeks] Amazon Question

2011-11-13 Thread UTKARSH SRIVASTAV
@Surinder give some proof or logic On Sun, Nov 13, 2011 at 10:25 AM, surender sanke wrote: > @nitin > yes i meant the same, if each different character have equal number of > frequency like abcabcabc a's -3, b's - 3 c's- 3 > then resultant string size is 2 else 1 > > surender > > > On Sun, Nov 1

Re: [algogeeks] Amazon Question

2011-11-12 Thread surender sanke
@nitin yes i meant the same, if each different character have equal number of frequency like abcabcabc a's -3, b's - 3 c's- 3 then resultant string size is 2 else 1 surender On Sun, Nov 13, 2011 at 12:21 AM, Ankur Garg wrote: > @Srinivas > > Wat if the string is abc > then it reduces to cc :)

Re: [algogeeks] Amazon Question

2011-11-12 Thread Ankur Garg
@Srinivas Wat if the string is abc then it reduces to cc :) ...So size 2 can also be there.so u cant say it will be 1 "always" On Sun, Nov 13, 2011 at 12:01 AM, Srinivasa Chaitanya T < tschaitanya@gmail.com> wrote: > > > On Sat, Nov 12, 2011 at 4:24 PM, Snoopy Me wrote: > >> Given a string

Re: [algogeeks] Amazon Question

2011-11-12 Thread Srinivasa Chaitanya T
On Sat, Nov 12, 2011 at 4:24 PM, Snoopy Me wrote: > Given a string consisting of a,b and c's, we can perform the > following > operation: > Take any two adjacent distinct characters and replace it with the > third character. For example, if 'a' and 'c' are adjacent, they can > replaced with 'b'.

Re: [algogeeks] Amazon Question

2011-11-12 Thread Ankur Garg
Hey I coded it . The answer is either 2 or 1 ..So I guess you guys are rite :) Here is the code void smallestString(string &str){ if(str.empty()) return; int j=0,i,k=0; for(i=1;i0)j--; i=j; } } } On Sat, Nov 12, 2011 at 8:19 PM, Nitin Garg wrote: > If yes, how d

Re: [algogeeks] Amazon Question

2011-11-12 Thread Nitin Garg
If yes, how do you prove it? On Sat, Nov 12, 2011 at 8:18 PM, Nitin Garg wrote: > I can prove that the size of resulting string will be 1 or 2. > > @surender - > what do you mean by no of distinct characters? they are 3 in this case - > a,b and c. > Do you mean to say that the no. of times each c

Re: [algogeeks] Amazon Question

2011-11-12 Thread Ankur Garg
Did they ask you to code this or just asked logic On Sat, Nov 12, 2011 at 4:57 PM, surender sanke wrote: > @myself > > if number of distinct characters are equal then its final string size is 2. > else there are more repeated characters other than distinct characters > then its 1 > > correct m

Re: [algogeeks] Amazon Question

2011-11-12 Thread Nitin Garg
I can prove that the size of resulting string will be 1 or 2. @surender - what do you mean by no of distinct characters? they are 3 in this case - a,b and c. Do you mean to say that the no. of times each character appears are equal then the final string is of size 2. and 1 otherwise? On Sat,

Re: [algogeeks] Amazon Question

2011-11-12 Thread surender sanke
@myself if number of distinct characters are equal then its final string size is 2. else there are more repeated characters other than distinct characters then its 1 correct me !!! surender On Sat, Nov 12, 2011 at 4:46 PM, surender sanke wrote: > All distinct combinations will result in string

Re: [algogeeks] Amazon Question

2011-11-12 Thread surender sanke
All distinct combinations will result in string size of 2 + rest repeated characters eg abcabcabc ->aabbcc->abc->aa or bb or cc surender On Sat, Nov 12, 2011 at 4:24 PM, Snoopy Me wrote: > Given a string consisting of a,b and c's, we can perform the > following > operation: > Take any two adja

[algogeeks] Amazon Question

2011-11-12 Thread Snoopy Me
Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this o

[algogeeks] Amazon Interview Question

2011-11-12 Thread Snoopy Me
Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this

Re: [algogeeks] Amazon Interview Question

2011-11-10 Thread UTKARSH SRIVASTAV
one = zero = 0; two = n-1; //n is length of string while(two>=one) { switch(a[one]) On Mon, Oct 24, 2011 at 9:50 PM, praveen raj wrote: > This can be done in O(n).. > > first shift all the 2's to the right side in O(n)... > > then again shift 1to the right shift b efore 2's. in O

Re: [algogeeks] Amazon Interview Question

2011-11-10 Thread UTKARSH SRIVASTAV
sorry it was incomplete On Fri, Nov 11, 2011 at 2:53 AM, UTKARSH SRIVASTAV wrote: one = zero = 0; two = n-1; //n is length of string while(two>=one) { switch(a[one]) { case '0' : swap(a[zero],z[one]); one++;zero++;break; case '1' : one++; break; case

Re: [algogeeks] Amazon Onsite

2011-11-01 Thread sravanreddy001
#include int main(){ //int pet[5]={10,1,19,19,1}; int pet[5]={10,1,18,20,1}; int point[5] = {10,20,30,40,50}; int tmp[5],index=0; int i; tmp[0]=pet[0]; for(i=1;i<5;i++){ tmp[i]= pet[i]+tmp[i-1]; printf("%d, %d

Re: [algogeeks] Amazon Onsite

2011-10-24 Thread Ankur Garg
I think this can be solved like this . Start from the first petrol pump i.e first point in the circle . Now if the petrol finishes befor reaching the second petrol pump that means we chose the incorrect point . So , choose second petrol pump now. If u reach third, fill ur tanker and move to 4th . N

Re: [algogeeks] Amazon Onsite

2011-10-24 Thread ravindra patel
@Nitin, excellent algo. >> if S < 0 && j = i-1 return 0 // I believe this mean there is no solution, you might want to return -1. Thanks, - Ravindra On Mon, Oct 24, 2011 at 8:39 PM, Nitin Garg wrote: > Lets say the Amount of petrol is Pi and distance to next petrol pump is Di > for ith petro

Re: [algogeeks] Amazon Onsite

2011-10-24 Thread Nitin Garg
Lets say the Amount of petrol is Pi and distance to next petrol pump is Di for ith petrol pump. start from i=1, j=1 S =0 while (i<=n) S += Pj - Dj; if S >= 0 && j = i-1 return i if S < 0 && j = i-1 return 0 else if S >= 0 j++ mod n; else if S < 0 j ++ mod n, i = j , S = 0; return 0

Re: [algogeeks] Amazon Interview Question

2011-10-24 Thread praveen raj
This can be done in O(n).. first shift all the 2's to the right side in O(n)... then again shift 1to the right shift b efore 2's. in O(n)... With regards, Praveen Raj DCE-IT 3rd yr 735993 praveen0...@gmail.com On Mon, Sep 26, 2011 at 6:23 PM, Naren s wrote: > dutch national fl

Re: [algogeeks] Amazon Onsite

2011-10-24 Thread praveen raj
I will choose the point where amount of fuel is maximum choose the shortest path from two direction (clockwise or anticlockwise).. With regards, Praveen Raj DCE-IT 3rd yr 735993 praveen0...@gmail.com On Mon, Oct 24, 2011 at 4:36 PM, Aniket wrote: > Suppose there is a circle. You

[algogeeks] Amazon Onsite

2011-10-24 Thread Aniket
Suppose there is a circle. You have five points on that circle. Each point corresponds to a petrol pump. You are given two sets of data. 1. The amount of petrol that petrol pump will give. 2. Distance from that petrol pump tp the next petrol pump. (Assume for 1 lit Petrol the truck will go 1 km)

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-20 Thread ravindra patel
@Anshu looks interesting. A few things - >> To check the particular number square can be written as sum of two squares or not. If it has any prime factor x such that x % 4 == 1 then only. - What would be the complexity of finding prime factors. Did you factor in it in overall complexity.

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-20 Thread anshu mishra
@Ravindra To check the particular number square can be written as sum of two squares or not. If it has any prime factor x such that x % 4 == 1 then only. Now about time complexity. suppose u have given array is. 10 6 13 9 17 4 18 12 1 5. now u can easily skip the numbers(1, 4, 6, 9, 12, 18);

Re: [algogeeks] Amazon Ques Suggest Algo

2011-10-20 Thread anshu mishra
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 sum will be zero and (index of first apperance of this number + 1) in sumar will be the start index.

Re: [algogeeks] Amazon Ques Suggest Algo

2011-10-20 Thread SUMANTH M
- 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[] = {1,2,-4,-3, 6 ,-3}; s[] = { 1,3,-1,-4,2,-1 }; In the sum array we have dupl

[algogeeks] Amazon Ques Suggest Algo

2011-10-19 Thread Ankur Garg
{You are given an unsorted array of integers. You have to find out the first sub array whose elements when added sum up to zero. eg:- int Array[] = {1,2,-4,-3, 6 ,-3.}Here sub array is -3,6,-3 bcos adding all these sum to zero. A sub array can be of size 2 to whole length of the array. You can

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-19 Thread sravanreddy001
Sorry.. this is good one, but works for consecutive numbers only from 1..N -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/07wiKGP2WusJ. To post to this g

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-19 Thread ravindra patel
@Anshu >> first check that particular number can be written as the sum of two squares or not What would be the way to figure it out. >> O(n * (number of side which is largest one for any triplet)) Didn't get it. Thanks, - Ravindra On Wed, Oct 19, 2011 at 11:09 AM, anshu mishra wrote: > @Ravind

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-18 Thread anshu mishra
@Ravindra may be the interviewer wants from u that instead of blindly checking for every number. first check that particular number can be written as the sum of two squares or not if yes than only search for that number. So the order will be decrease from O(n^2) to O(n * (number of side which is la

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-17 Thread Ankur Garg
@Shashank ..+1 ..I wud say he must be given a tuning award :D :D for solving such eternal conundrum ;) On Mon, Oct 17, 2011 at 2:37 PM, WgpShashank wrote: > @wladimir , its PPT (Pythagoras triplets ) but its number theory based > approach http://en.wikipedia.org/wiki/Pythagorean_triple might

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-17 Thread Ankur Garg
*Turing :P On Mon, Oct 17, 2011 at 3:51 PM, Ankur Garg wrote: > @Shashank ..+1 ..I wud say he must be given a tuning award :D :D for > solving such eternal conundrum ;) > > > > On Mon, Oct 17, 2011 at 2:37 PM, WgpShashank > wrote: > >> @wladimir , its PPT (Pythagoras triplets ) but its number

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-17 Thread WgpShashank
@wladimir , its PPT (Pythagoras triplets ) but its number theory based approach http://en.wikipedia.org/wiki/Pythagorean_triple might not be good idea Here is approach : * * *Euclid's formula*[1] is a fundamental formula for genera

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-15 Thread sravanreddy001
This appears to be n^(3/2) complexity, looking at one of the solutions in http://stackoverflow.com/questions/575117/pythagorean-triplets assuming elements as sorted. (x cannot be greater than sqrt(2z) as x2+y2 = z2 --> for the worst value of y2 --> 2x^2 = z2 MaxX = ( 2 * N - 1 ) ** 0.5 for x

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-14 Thread Ashish Goel
http://stackoverflow.com/questions/575117/pythagorean-triplets Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Fri, Oct 14, 2011 at 3:14 PM, Ankur Garg wrote: > @Rahul > > Pls elaborate with an example ... > > > On Fri, Oct 14, 2011 at 2:35 PM,

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-14 Thread Bittu Sarkar
@rahul It still will be O(n^2) time complexity On 14 October 2011 15:14, Ankur Garg wrote: > @Rahul > > Pls elaborate with an example ... > > > On Fri, Oct 14, 2011 at 2:35 PM, rahul patil < > rahul.deshmukhpa...@gmail.com> wrote: > >> You can take advantage of a basic property of triagle that >

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-14 Thread rahul patil
suppose sorted array is 1,2,3,5,10,12,13,17,19,25 so if u want to find possible combinations, with 25 as hypotenuse, then only range 10 ... 19 could have answer as 19 + 10 > 25 On Fri, Oct 14, 2011 at 3:14 PM, Ankur Garg wrote: > @Rahul > > Pls elaborate with an example ... > > > On Fri, Oct

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-14 Thread Siddharth Pipriya
using properties of tiangle wont help i guess. the will give the range of VALUES you want to restrict yourself to. not the range of INDEX's of the array... On Fri, Oct 14, 2011 at 3:14 PM, Ankur Garg wrote: > @Rahul > Pls elaborate with an example ... > > On Fri, Oct 14, 2011 at 2:35 PM, rahul pa

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-14 Thread Ankur Garg
@Rahul Pls elaborate with an example ... On Fri, Oct 14, 2011 at 2:35 PM, rahul patil wrote: > You can take advantage of a basic property of triagle that > > sum of largest side of triangle < sum of other two sides, > > After sorting you could easily deside the range in which possible solution >

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-14 Thread rahul patil
You can take advantage of a basic property of triagle that sum of largest side of triangle < sum of other two sides, After sorting you could easily deside the range in which possible solution could be found for a chosen hypotenuse On Fri, Oct 14, 2011 at 11:10 AM, ravindra patel wrote: > @Wladi

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread ravindra patel
@Wladimir, yeah I have heard about that. Another way of populating primitive pythagoreans is, for any natural number m > 1 (m^2 - 1, 2m, m^2 + 1) forms a pythagorean triplet. This is useful in populating pythagorean tiplets but here the problem is to search such triplets from a given int array. @

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread Ankur Garg
@rahul...How do u choose z and x for computing z^2 -x^2 ? On Thu, Oct 13, 2011 at 11:34 PM, rahul wrote: > You can create a hash with sqrt(z2-x2). This will make it o(n). The > interviewer just made it lil tricky. That's all > > -- > You received this message because you are subscribed to the Go

[algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread rahul
You can create a hash with sqrt(z2-x2). This will make it o(n). The interviewer just made it lil tricky. That's all -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/alg

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread Ankur Garg
BTW can we solve this by hashing..That is the only feasible solution which comes to my mind to reduce the time complexity ? On Thu, Oct 13, 2011 at 11:20 PM, Ankur Garg wrote: > Dude this is nothing but 3 sum problem > > http://en.wikipedia.org/wiki/3SUM > > Ask interviewer to check this link an

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread praveen raj
N2 would me minimum On 13-Oct-2011 11:08 PM, "ravindra patel" wrote: > Hi, > Another question I faced in Amazon F2F. > > Given an unsorted array of integers, find all triplets that satisfy x^2 + > y^2 = z^2. > > For example if given array is - 1, 3, 7, 5, 4, 12, 13 > The answer should be - >

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread Ankur Garg
Dude this is nothing but 3 sum problem http://en.wikipedia.org/wiki/3SUM Ask interviewer to check this link and say he has gone mad!! :P Regards Ankur On Thu, Oct 13, 2011 at 10:29 PM, ravindra patel wrote: > Hi, > Another question I faced in Amazon F2F. > > Given an unsorted array of inte

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread Wladimir Tavares
I thinking in this property but i dont know how to use :( Euclid, in his book Elements, demonstrated that there is a infinnity of suits early Pythagoreans. Moreover, he found a formula that generates all primitive Pythagorean suits. Given two natural numbers m> n, the suit (a, b, c), where:

[algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread ravindra patel
Hi, Another question I faced in Amazon F2F. Given an unsorted array of integers, find all triplets that satisfy x^2 + y^2 = z^2. For example if given array is - 1, 3, 7, 5, 4, 12, 13 The answer should be - 5, 12, 13 and 3, 4, 5 I suggested below algo with complexity O(n^2) - - Sort the

Re: [algogeeks] amazon,microsoft link list probs

2011-10-05 Thread Ankur Garg
Implement recursive merge sort for first question For second just swap the values of node and node b On Wed, Oct 5, 2011 at 9:18 PM, 9ight coder <9ightco...@gmail.com> wrote: > 1.perform inplace(we cant create new node)merge sort of two sorted > linked list.(asked in amazon 1 mon before) > 2.a

[algogeeks] amazon,microsoft link list probs

2011-10-05 Thread 9ight coder
1.perform inplace(we cant create new node)merge sort of two sorted linked list.(asked in amazon 1 mon before) 2.a->b->c->d->e convert to b->a->d->c->e without creating new node. (asked in microsoft on 4rth oct at thapar). sugeest solutions. -- You received this message because you are

[algogeeks] Amazon Ques

2011-10-04 Thread Ankur Garg
Find out the smallest segment in a document containing all the given words. Desired Complexity is O nlogK ..n is the total no of words in the document and k is the number of input words -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post

[algogeeks] amazon writtwen test

2011-10-02 Thread gaurav kumar
25 objective questions focused on operatig system basic commands of linux aptitude - 4-5 questions rest on algos, ds, c nd c++ 3 subjective questions 1) merge two sorted link list 2) u have given coins of vrious denominations and u have to make a sum with min. no. of coins 3) an amazon own alogo fo

Re: [algogeeks] amazon ques

2011-09-30 Thread manish kapur
@adi.. he gave a hint that space used should not b of order of range of numbers but should depend on how many numbers are inserted... eg..if range is say 1000...bt u entered only 5 nos ->8,100,202,600,989. u can use space of order 5..and not 1000 -- You received this message because you are subs

Re: [algogeeks] amazon ques

2011-09-30 Thread manish kapur
@somnath...can u pls elaborate... he was looking for an elaborate ans... -- 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

[algogeeks] Amazon Interns

2011-09-30 Thread shiva@Algo
Amazon is Coming in our college ,Plz sugeest which subjects and what topic to focus for that ... -- 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 gro

Re: [algogeeks] amazon ques

2011-09-30 Thread SAMM
Linked List + Hash table will serve the purpose in O(1). On 9/30/11, Adi Srikanth wrote: > if space complexity is not a constraint..u can use any kind of hashing and > its function.depends on the kind of data we store..if its numbers go for > square or simple linear function > > > Regards

Re: [algogeeks] Amazon -> array problem

2011-09-30 Thread Hatta
just in case... start with: algo(1,0) On Fri, Sep 30, 2011 at 7:07 PM, Hatta wrote: > char A[] = { 1,2,3,4,5 }; > int algo(int b, int i) { >    if(i == sizeof(A)) { return 1; } >    int c = A[i]; >    int f = algo(b*c, i+1); >    A[i] = b*f; >    return f*c; > } > > > On Thu, Sep 29, 2011 at 8:2

Re: [algogeeks] Amazon -> array problem

2011-09-30 Thread Hatta
char A[] = { 1,2,3,4,5 }; int algo(int b, int i) { if(i == sizeof(A)) { return 1; } int c = A[i]; int f = algo(b*c, i+1); A[i] = b*f; return f*c; } On Thu, Sep 29, 2011 at 8:26 AM, raju wrote: > Given an integer array. { 1,2,3,4,5 } > Compute array containing elements > 120,6

Re: [algogeeks] Amazon -> array problem

2011-09-30 Thread Nitin Garg
@raju - so it means the input array should be distorted to give the output array. Are you sure about it? i doubt if its possible. On Fri, Sep 30, 2011 at 11:24 PM, raju wrote: > @nitin .. > Output array is not a new array ... you can do anything to input array .. > > ~raju > > > On Fri, Sep 30,

Re: [algogeeks] Amazon -> array problem

2011-09-30 Thread raju
@nitin .. Output array is not a new array ... you can do anything to input array .. ~raju On Fri, Sep 30, 2011 at 1:24 PM, Nitin Garg wrote: > Can we assume the output array is a new array and we can distort the > originial array??? > > > On Fri, Sep 30, 2011 at 9:14 AM, praveen raj wrote: > >>

Re: [algogeeks] amazon ques

2011-09-30 Thread Adi Srikanth
if space complexity is not a constraint..u can use any kind of hashing and its function.depends on the kind of data we store..if its numbers go for square or simple linear function Regards, Adi Srikanth. Mob No 9887233349 Personal Pages: adisrikanth.co.nr On Fri, Sep 30, 2011 at 9:43 PM

Re: [algogeeks] amazon ques

2011-09-30 Thread Devesh Mittal
Fibonacci Heaps On Fri, Sep 30, 2011 at 9:14 PM, manish kapur wrote: > u have to perform following tasks in O(1) time > 1.)insertion > 2.)deletion > 3.)searching > no range of input numbers is given > wat data structure will you use? > if u use hashing wat will be the key and value pairs? > > --

[algogeeks] amazon ques

2011-09-30 Thread manish kapur
u have to perform following tasks in O(1) time 1.)insertion 2.)deletion 3.)searching no range of input numbers is given wat data structure will you use? if u use hashing wat will be the key and value pairs? -- You received this message because you are subscribed to the Google Groups "Algorithm G

Re: [algogeeks] Amazon -> array problem

2011-09-30 Thread Nitin Garg
Can we assume the output array is a new array and we can distort the originial array??? On Fri, Sep 30, 2011 at 9:14 AM, praveen raj wrote: > Take two array... one will take care of left products... and othr will take > care of right product.. at any index left[i]=A[i-1]*left[i-1] starting

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread praveen raj
Take two array... one will take care of left products... and othr will take care of right product.. at any index left[i]=A[i-1]*left[i-1] starting from left and right[i]= A[i+1]*right[i+1] starting frm right…… -- You received this message because you are subscribed to the Google Groups "Alg

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread Piyush Grover
sorry, one mistake... mul = mul*A[i]; it should be mul = mul*A[i+1] On Fri, Sep 30, 2011 at 2:57 AM, Piyush Grover wrote: > Given array A. > > Compute array B such that > > B[0] = 1; > for(i = 1; i < n; i++) > B[i] = B[i-1]*A[i-1] > > now, > mul = 1; > for (i = n-2; i >=0; i--){ >mul =

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread Piyush Grover
Given array A. Compute array B such that B[0] = 1; for(i = 1; i < n; i++) B[i] = B[i-1]*A[i-1] now, mul = 1; for (i = n-2; i >=0; i--){ mul = mul*A[i]; B[i] = B[i]*mul; } On Fri, Sep 30, 2011 at 2:18 AM, Hatta wrote: > are the algorithm instance always a sequence incremented by one

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread Hatta
are the algorithm instance always a sequence incremented by one? On Thu, Sep 29, 2011 at 8:26 AM, raju wrote: > Given an integer array. { 1,2,3,4,5 } > Compute array containing elements > 120,60,40,30,24 (2*3*4*5,1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4) > We shouldn't use division operator( / ) > Ti

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread Amol Sharma
check this http://www.geeksforgeeks.org/archives/7527 time O(n) space O(n) -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread raju
@ karthikeyan .. you're using O(n) space .. Try do it in O(n) time with O(1) space ... Array sorted or not doesn't matter !!! ~raju On Thu, Sep 29, 2011 at 9:20 PM, KARTHIKEYAN V.B. wrote: > > //use dynamic programming approach > > //it is O(n) time and O(1) space > > #include > #define N 5 >

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread KARTHIKEYAN V.B.
//use dynamic programming approach //it is O(n) time and O(1) space #include #define N 5 void main() { int a[N]={1,2,3,4,5},i; int prod1[N]; int p=1; for(i=0;i=0;--i) { prod2[i]=p; p*=a[i]; } int products[N]; for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread Shravan Kumar
whats the running time? isn't it O(n2) ? On Thu, Sep 29, 2011 at 8:54 PM, UTKARSH SRIVASTAV wrote: > maintain two arrays one left array having value left[i] = > a[0]*a[1]*a[2].a[i-1] and one right array having value > right[i]=a[i+1]*[i+2]a[n] and then to get > ans[i]...ans[i]=left[i

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread UTKARSH SRIVASTAV
maintain two arrays one left array having value left[i] = a[0]*a[1]*a[2].a[i-1] and one right array having value right[i]=a[i+1]*[i+2]a[n] and then to get ans[i]...ans[i]=left[i]*right[i] On Thu, Sep 29, 2011 at 8:16 PM, Ankur Garg wrote: > Is the array Sorted ? > > > > On Thu, Sep

Re: [algogeeks] Amazon -> array problem

2011-09-29 Thread Ankur Garg
Is the array Sorted ? On Thu, Sep 29, 2011 at 4:56 PM, raju wrote: > Given an integer array. { 1,2,3,4,5 } > Compute array containing elements > 120,60,40,30,24 (2*3*4*5,1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4) > > We shouldn't use division operator( / ) > Time complexity O(n) .. Space complexity O(

[algogeeks] Amazon -> array problem

2011-09-29 Thread raju
Given an integer array. { 1,2,3,4,5 } Compute array containing elements 120,60,40,30,24 (2*3*4*5,1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4) We shouldn't use division operator( / ) Time complexity O(n) .. Space complexity O(1) ~raju -- You received this message because you are subscribed to the Google

Re: [algogeeks] Amazon Ques

2011-09-28 Thread KARTHIKEYAN V.B.
reversing the linked list static void reverse(struct node** head_ref) { struct node* p=NULL; struct node* curr=*head_ref; struct node* q; while(curr!=NULL) { q=curr->next; curr->next=p; p=curr; curr=q; } *head_ref=p; } -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Amazon Ques

2011-09-27 Thread sukran dhawan
call function recursively when it is the last node, return the function calls and print it On Wed, Sep 28, 2011 at 8:20 AM, rahul sharma wrote: > make sure that u ryt the syntax correct > > > On Wed, Sep 28, 2011 at 8:18 AM, rahul sharma wrote: > >> reverse(head) >> { >> if(head==NUll) >> { >> pr

Re: [algogeeks] Amazon Ques

2011-09-27 Thread sukran dhawan
@rahul if(head == null) return; u cant print head->info when head is null On Wed, Sep 28, 2011 at 8:20 AM, rahul sharma wrote: > make sure that u ryt the syntax correct > > > On Wed, Sep 28, 2011 at 8:18 AM, rahul sharma wrote: > >> reverse(head) >> { >> if(head==NUll) >> { >> printf("head->info

Re: [algogeeks] Amazon Ques

2011-09-27 Thread rahul sharma
make sure that u ryt the syntax correct On Wed, Sep 28, 2011 at 8:18 AM, rahul sharma wrote: > reverse(head) > { > if(head==NUll) > { > printf("head->info"); > return; > } > reverse(head->link) > printf("head->info); > } > > On Wed, Sep 28, 2011 at 4:39 AM, anand karthik > wrote: > >> Reverse it

Re: [algogeeks] Amazon Ques

2011-09-27 Thread rahul sharma
reverse(head) { if(head==NUll) { printf("head->info"); return; } reverse(head->link) printf("head->info); } On Wed, Sep 28, 2011 at 4:39 AM, anand karthik wrote: > Reverse it , print it and reverse it again. :-) > > On Wed, Sep 28, 2011 at 3:28 AM, Ankur Garg wrote: > > Print Reverse of linked l

Re: [algogeeks] Amazon Ques

2011-09-27 Thread anand karthik
Reverse it , print it and reverse it again. :-) On Wed, Sep 28, 2011 at 3:28 AM, Ankur Garg wrote: > Print Reverse of linked list (dont reverse it) with only constant space. > > Recursion uses stack spaceO(n) ..so post some other solution .. > > > -- > You received this message because you are su

[algogeeks] Amazon Ques

2011-09-27 Thread Ankur Garg
Print Reverse of linked list (dont reverse it) with only constant space. Recursion uses stack spaceO(n) ..so post some other solution .. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegr

Re: [algogeeks] Amazon Interview Question

2011-09-26 Thread Naren s
dutch national flag problem..search in wiki...classical. On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote: > You are given a string (consisting of 0's, 1's or 2's) where 0 > represents a blue ball, 1 a > red ball, and 2 a black ball. Using only swap operations (counting > sort not allowed) > rearr

Re: [algogeeks] Amazon Interview Question

2011-09-26 Thread sukran dhawan
count the number of 0s 1s 2s.then store os first den 1s followed by 2s On Sat, Sep 24, 2011 at 9:55 AM, Anup Ghatage wrote: > Is this like the segregating all the 1's to the right and the 0's to the > left > or am i missing something? > > > On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote: > >> Y

Re: [algogeeks] Amazon Question

2011-09-26 Thread Deoki Nandan
can you tell how to write code to access log file On 26 September 2011 09:27, teja bala wrote: > do dfs traversal along the two log files and maintain a stack in which push > the element from 1st log file and if matching id in 2 log file is found pop > it and display it to user > but dis 'll tak

Re: [algogeeks] Amazon Question

2011-09-25 Thread teja bala
do dfs traversal along the two log files and maintain a stack in which push the element from 1st log file and if matching id in 2 log file is found pop it and display it to user but dis 'll take extra stack space ,,, another sol.. maintain a bit array for any of the log file and while doing BFS tr

Re: [algogeeks] Amazon Question

2011-09-25 Thread khushboo lohia
Are the customer id's in 2 files in sorted order ? On Mon, Sep 26, 2011 at 1:29 AM, Ankur Garg wrote: > You are given 2 log files each having 1 billion entries and each entry has > a unique customer id.You need to print the records in two files which are > common. > > > > -- > You received this

[algogeeks] Amazon Question

2011-09-25 Thread Ankur Garg
You are given 2 log files each having 1 billion entries and each entry has a unique customer id.You need to print the records in two files which are common. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to

Re: [algogeeks] Amazon OS question

2011-09-24 Thread Sanjay Rajpal
yah rite answer would be 5 and 4 resp. Sanju :) On Sat, Sep 24, 2011 at 10:04 PM, Dheeraj Sharma < dheerajsharma1...@gmail.com> wrote: > 5 & 4? > > > On Sun, Sep 25, 2011 at 9:33 AM, sivaviknesh s wrote: > >> >> >> >> A parallel program consists of 8 tasks – T1 through T8. Each task requires >>

Re: [algogeeks] Amazon OS question

2011-09-24 Thread Dheeraj Sharma
5 & 4? On Sun, Sep 25, 2011 at 9:33 AM, sivaviknesh s wrote: > > > > A parallel program consists of 8 tasks – T1 through T8. Each task requires > one time step to be executed on a single processor. Let X -> Y denote the > fact that task X must be executed before task Y is executed. Suppose only >

[algogeeks] Amazon OS question

2011-09-24 Thread sivaviknesh s
A parallel program consists of 8 tasks – T1 through T8. Each task requires one time step to be executed on a single processor. Let X -> Y denote the fact that task X must be executed before task Y is executed. Suppose only the tasks X, Y are to be executed. On any multiprocessor machine it would re

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread shady
@guarav true @others no point in sending the code describe your logic... anyway link provided by guarav is suffice to solve the problem On Sat, Sep 24, 2011 at 5:26 PM, Gaurav Aggarwal wrote: > Classic problem http://en.wikipedia.org/wiki/Dutch_national_flag_problem > > > > On Sat, Sep 24

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread Nitin Garg
Keep two pointers - p1 and p2 p1 points at the index just after last 0 such that there are all zero's before it. p2 points at the entry just before last 2, and there are all 2's after it. *example*- 0010201201222 p1 = 2; p2 = 9; *Pseudo code - * p1 = 0; p2 = n-1; i = 0; while(i wrote: > we cant

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread Gaurav Aggarwal
Classic problem http://en.wikipedia.org/wiki/Dutch_national_flag_problem On Sat, Sep 24, 2011 at 5:15 PM, Ankur Garg wrote: > void sort012(int a[],int n){ > int i = 0, s = 0, last = n-1; > while(i<=last){ >if(a[i] == 0 && i!=s) > { >swap(a[i], a[s]); >s+

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread Ankur Garg
void sort012(int a[],int n){ int i = 0, s = 0, last = n-1; while(i<=last){ if(a[i] == 0 && i!=s) { swap(a[i], a[s]); s++; } else if(a[i] == 2 && i!=last) { swap(a[i], a[last]); last--; } else i++; } } On Sat, Sep 24, 2011 at 5:13

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread Ankit Sinha
I think this will do the same: - #include "stdafx.h" #include "stdlib.h" void swap(int *a, int start, int end) { int temp; temp = *(a + start); *(a + start) = *(a + end); *(a + end) = temp; } int _tmain(int argc, _TCHAR* argv[]) { int minIndex=0, maxIndex=

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread malay chakrabarti
dutch national flag problem :) On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma wrote: > i think this travels only once ... correct me if am wrong > #include > #include > #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) > int main() > { > int t,x; > scanf("%d",&t); > while(t--) > { >

Re: [algogeeks] Amazon Interview Question

2011-09-24 Thread Dheeraj Sharma
i think this travels only once ... correct me if am wrong #include #include #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf("%d",&t); while(t--) { char str[100]; scanf("%s",str); int i=0,j=0,k=strlen(str)-1;

Re: [algogeeks] Amazon Interview Question

2011-09-23 Thread Yogesh Yadav
we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string "102112011" so w

Re: [algogeeks] Amazon Interview Question

2011-09-23 Thread Dheeraj Sharma
char str[100],t; scanf("%s",str); char ch='0'; int i=0,j=0; while(j wrote: > Is this like the segregating all the 1's to the right and the 0's to the > left > or am i missing something? > > > On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote: >

Re: [algogeeks] Amazon Interview Question

2011-09-23 Thread Anup Ghatage
Is this like the segregating all the 1's to the right and the 0's to the left or am i missing something? On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote: > You are given a string (consisting of 0's, 1's or 2's) where 0 > represents a blue ball, 1 a > red ball, and 2 a black ball. Using only swap

<    1   2   3   4   5   6   7   8   >