Re: [algogeeks] amazon question

2012-10-23 Thread bharat b
If the requirement is only searching in 3-D .. there is a famous data structure K-D tree. On Tue, Oct 23, 2012 at 5:54 PM, bharat b wrote: > we can represent in 3-D array .. > what type of elements are those .. is there any special kind of formation > among elements for searching? we have to thin

Re: [algogeeks] amazon question

2012-10-23 Thread bharat b
we can represent in 3-D array .. what type of elements are those .. is there any special kind of formation among elements for searching? we have to think about searching based on the criteria .. On Tue, Oct 23, 2012 at 3:34 PM, saket wrote: > We have a long chain of cuboids in all the six direct

Re: [algogeeks] Amazon question

2012-03-22 Thread Amol Sharma
but the worst case still remains O(sqrt(E)) -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Fri, Ma

Re: [algogeeks] Amazon question

2012-03-22 Thread Rujin Cao
@atul: Anurag's code has illustrated the idea of O(sqrt(E)) solution. One more thing to optimize is that we can safely break after finding the first factor of E which is less than sqrt(E). So the code could be changed to: #include#include#include#include#includeusing namespace std;#define INFY 10

Re: [algogeeks] Amazon question

2012-03-21 Thread atul anand
@Rujin : mathematically point 2.2 seems straight forward but can we achieve value of x and y with an algo whose complexity wud be O(sqrt(E)) ?? On Wed, Mar 21, 2012 at 2:37 PM, Rujin Cao wrote: > One possible way is: > > 1) Put the three candidate number together into an array [n, n + 1, n + 2]

Re: [algogeeks] Amazon question

2012-03-21 Thread Rujin Cao
One possible way is: 1) Put the three candidate number together into an array [n, n + 1, n + 2] 2) Iterate each element *E* in that array and test whether *E* is a prime number 2.1) If it is, there will be only one way to find the two numbers product to be *E*, i.e. {x = 1, y = E} OR {x =

Re: [algogeeks] Amazon Question

2011-11-14 Thread Nitin Garg
@surendra - converse is not true. aabbcc will be reduced 2. aabbcc can be reduced to acbcc acbcc has unequal number of a's,b's and c's. Hence it should be reducable to 1. On Sun, Nov 13, 2011 at 3:42 PM, Anika Jain wrote: > its coming out be either 1 or 2 in all cases > > > On Sun, Nov 13, 2011

Re: [algogeeks] Amazon Question

2011-11-13 Thread Anika Jain
its coming out be either 1 or 2 in all cases On Sun, Nov 13, 2011 at 1:55 PM, UTKARSH SRIVASTAV wrote: > @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 >> freque

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

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

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:

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

Re: [algogeeks] Amazon question SDE

2011-09-20 Thread saurabh agrawal
@yogesh, yes you are right. It is not an array, but an abstraact data type which supports, insertion with index. On Tue, Sep 20, 2011 at 5:18 PM, Yogesh Yadav wrote: > @saurabh: > > i think may be u left some part of question to mention... the array may be > a heap array ... > > or if the ques

Re: [algogeeks] Amazon question SDE

2011-09-20 Thread Yogesh Yadav
@saurabh: i think may be u left some part of question to mention... the array may be a heap array ... or if the ques is correct then i don't think this sum can be possible in O(log n) for previously existing array... may be we have to make array from start...then as you mention we can use anot

Re: [algogeeks] Amazon question SDE

2011-09-20 Thread vishnu VR
This can be done using binary indexed tree. Thanks and Regards, Vishnu Vardan Reddy Onteddu Software Engineer KeyPoint Technologies India Pvt Ltd. 9Q1A, 9th Floor, Cyber Towers, HITEC City, Madhapur, Hyderabad – 500081. T: +91 40 40337000 Extn 70__ F: +91 40 40337070 www.keypoint-tech.com Be

Re: [algogeeks] Amazon question

2011-08-20 Thread Jagannath Prasad Das
@naren:a[i] may exceed array limit.sigsegv error amy result On Sat, Aug 20, 2011 at 9:08 PM, Naren s wrote: > > > On Sat, Aug 20, 2011 at 9:07 PM, Naren s wrote: > >> for(i=0 to n) >> { >> if(a[abs(a[i])-1]>0) >> a[abs(a[i])-1] = -a[abs(a[i])-1]; >> else >> printf("%d",abs(a[i])); >> >> }

Re: [algogeeks] Amazon question

2011-08-20 Thread Naren s
On Sat, Aug 20, 2011 at 9:07 PM, Naren s wrote: > for(i=0 to n) > { > if(a[abs(a[i])-1]>0) > a[abs(a[i])-1] = -a[abs(a[i])-1]; > else > printf("%d",abs(a[i])); > } > > space : o(n) > time : o(1) > > > > On Fri, Aug 19, 2011 at 12:45 AM, *$* wrote: > >> How to find duplicate element (only one ele

Re: [algogeeks] Amazon question

2011-08-20 Thread Naren s
for(i=0 to n) { if(a[abs(a[i])-1]>0) a[abs(a[i])-1] = -a[abs(a[i])-1]; else printf("%d",a[abs(a[i])]); } space : o(n) time : o(1) On Fri, Aug 19, 2011 at 12:45 AM, *$* wrote: > How to find duplicate element (only one element is repeated) from an array > of unsorted positive integers.. > time c

Re: [algogeeks] Amazon Question

2011-08-18 Thread hary rathor
bitset is best . require only 32 time less then require in hash table . -- 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+

Re: [algogeeks] Amazon Question

2011-08-18 Thread sagar pareek
Common yaar its very simple it is good for u to go in deep hence google it or refer a good data structure book On Thu, Aug 18, 2011 at 5:36 PM, Ankur Garg wrote: > Can u provide a bit detail bro !! > > > On Thu, Aug 18, 2011 at 8:04 AM, sagar pareek wrote: > >> Hashing >> :) >> >> On Thu, Aug 18

Re: [algogeeks] Amazon Question

2011-08-18 Thread Anantha Krishnan
Refer here . On Thu, Aug 18, 2011 at 5:36 PM, Ankur Garg wrote: > Can u provide a bit detail bro !! > > > On Thu, Aug 18, 2011 at 8:04 AM, sagar pareek wrote: > >> Hashing >> :) >> >> On Thu, Aug 18, 2011 at 5:30 PM, Ankur Garg wrote: >> >>> Define a data structure , us

Re: [algogeeks] Amazon Question

2011-08-18 Thread Anantha Krishnan
We can use hash to do all the operations in O(1) time. Thanks & Regards, Anantha Krishnan On Thu, Aug 18, 2011 at 5:30 PM, Ankur Garg wrote: > Define a data structure , using extra memory/space , such that : > > Insert(int a) > Delete(int a) > isPresent(int a) > get(int a) > > All above operati

Re: [algogeeks] Amazon Question

2011-08-18 Thread Ankur Garg
Can u provide a bit detail bro !! On Thu, Aug 18, 2011 at 8:04 AM, sagar pareek wrote: > Hashing > :) > > On Thu, Aug 18, 2011 at 5:30 PM, Ankur Garg wrote: > >> Define a data structure , using extra memory/space , such that : >> >> Insert(int a) >> Delete(int a) >> isPresent(int a) >> get(int

Re: [algogeeks] Amazon Question

2011-08-18 Thread sagar pareek
Hashing :) On Thu, Aug 18, 2011 at 5:30 PM, Ankur Garg wrote: > Define a data structure , using extra memory/space , such that : > > Insert(int a) > Delete(int a) > isPresent(int a) > get(int a) > > All above operations on the defined data structure take O(1) , i.e. > constant time. > > > Any su

Re: [algogeeks] amazon question

2011-08-16 Thread Suganya Palaniappan
@rajeev : Can u pls explain the second approach...?? On Mon, Aug 15, 2011 at 10:09 PM, sandeep pandey < sandeep.masum4...@gmail.com> wrote: > dyamic programming. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group,

Re: [algogeeks] amazon question

2011-08-15 Thread sandeep pandey
dyamic programming. -- 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, visi

Re: [algogeeks] amazon question

2011-08-15 Thread rajeev bharshetty
First approach : I think you can solve the above problem using Levenshtein Distance (edit distance which is basically no of operations required to transform word1 to word2) . Algo can be found here http://en.wikipedia.org/wiki/Levenshtein_distance Second approach : Store the words in trie data

Re: [algogeeks] Amazon question.

2011-08-09 Thread programming love
*Executing code with printf's for each iteration for better understanding.* #include main(){ int n, i, j, k, t1=0, t2=0, t3, a[30]; printf("Enter the number of elements\n"); scanf("%d", &n); for(i=0; i=0;k--){ printf("iteration %d\n", t2); for(j=k,i=0;(ihttp://groups.google.com/group/algogeeks?

Re: [algogeeks] Amazon question.

2011-08-09 Thread ankit sambyal
1. Square each element of the array and then sort it---O(nlogn) 2. for(i=0;i<(size-3);i++) { j=i+1; k=size-1; while(jhttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Amazon Question

2011-08-08 Thread Raman
Ok I got it.. for 2 processors 1->2 (2 steps) (On any processor) 3 4 (1 step) (parallel) 5 6 (1 step) (parallel) 7 8 (1 step) (parallel) total 5 steps -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visi

Re: [algogeeks] Amazon Question

2011-08-08 Thread Raman
@aditi: How did u do the 4th one?? -- 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/-/rZ25FTEocVEJ. To post to this group, send email to algogeeks@googlegroups

Re: [algogeeks] amazon question

2011-08-08 Thread shady
doesn't matter if the condition is == 0 or != 0 answer will always be 3. On Tue, Aug 9, 2011 at 12:04 AM, aditi garg wrote: > well since i have told u i dont knw OS too well so i ws nt sure...bt if > suppose the condition (p1==0) is false thn only 1 child will be created?? > > > On Mon, Aug 8,

Re: [algogeeks] amazon question

2011-08-08 Thread aditi garg
@sagar: Thanx a lot On Tue, Aug 9, 2011 at 12:15 AM, sagar pareek wrote: > * > void main() { > > int p1= fork(); > > if (p1 == 0) { > > int p2 = fork(); > > if (p2 != 0) { > > fork(); > > } > > } > > } > > for confi

Re: [algogeeks] amazon question

2011-08-08 Thread sagar pareek
* void main() { int p1= fork(); if (p1 == 0) { int p2 = fork(); if (p2 != 0) { fork(); } } } for confirmation just make a diagram M

Re: [algogeeks] amazon question

2011-08-08 Thread aditi garg
well since i have told u i dont knw OS too well so i ws nt sure...bt if suppose the condition (p1==0) is false thn only 1 child will be created?? On Mon, Aug 8, 2011 at 11:56 PM, ankit sambyal wrote: > @aditi : the ans is 3. Why do u think there is no definite ans ? > > -- > You received this m

Re: [algogeeks] amazon question

2011-08-08 Thread ankit sambyal
@aditi : the ans is 3. Why do u think there is no definite 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+unsubsc

Re: [algogeeks] amazon question

2011-08-08 Thread aditi garg
I dnt think thr wud be a definite ans On Mon, Aug 8, 2011 at 11:26 PM, siddharam suresh wrote: > is it 3 ? > Thank you, > Siddharam > > > > On Mon, Aug 8, 2011 at 11:24 PM, rajul jain wrote: > >> How many Children process following program produce >> * >> void main() { >> >> int p1= f

Re: [algogeeks] amazon question

2011-08-08 Thread Kamakshii Aggarwal
3? On Mon, Aug 8, 2011 at 11:26 PM, siddharam suresh wrote: > is it 3 ? > Thank you, > Siddharam > > > > On Mon, Aug 8, 2011 at 11:24 PM, rajul jain wrote: > >> How many Children process following program produce >> * >> void main() { >> >> int p1= fork(); >> >> if (p1 == 0) { >>

Re: [algogeeks] amazon question

2011-08-08 Thread siddharam suresh
is it 3 ? Thank you, Siddharam On Mon, Aug 8, 2011 at 11:24 PM, rajul jain wrote: > How many Children process following program produce > * > void main() { > > int p1= fork(); > > if (p1 == 0) { > > int p2 = fork(); > > if (p2 != 0) { > >

Re: [algogeeks] amazon question

2011-08-08 Thread rajul jain
How many Children process following program produce * void main() { int p1= fork(); if (p1 == 0) { int p2 = fork(); if (p2 != 0) { fork(); } } } * On Mon, Aug 8, 2011 at 11:11 AM, Kamakshii Aggarwal wrote: >

Re: [algogeeks] Amazon Question

2011-08-08 Thread dilip makwana
Yes answer to third is 1:1 ... see this link for it http://www.mytechinterviews.com/boys-and-girls On 8 August 2011 20:00, Gyanendra Kumar wrote: > i think for 3rd it shud be c.)1:1 > > > On Mon, Aug 8, 2011 at 7:56 PM, rajeev bharshetty wrote: > >> 4) b >> 3) a >> >> Correct me if i am wrong >

Re: [algogeeks] Amazon Question

2011-08-08 Thread aditi garg
2.b 3.c 4.c On Mon, Aug 8, 2011 at 8:12 PM, sagar pareek wrote: > 1. O(n) > 2. b > 4 c > > On Mon, Aug 8, 2011 at 8:08 PM, programming love < > love.for.programm...@gmail.com> wrote: > >> 1. O(n) >> 2.b >> 4.c >> >> >> On Mon, Aug 8, 2011 at 7:24 PM, ankit sambyal wrote: >> >>> Plz give the ans

Re: [algogeeks] Amazon Question

2011-08-08 Thread Brijesh Upadhyay
Yeah.. 3rd answer is 1:1 , for reference http://discuss.fogcreek.com/techInterview/default.asp?cmd=show&ixPost=150 -- 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/algo

Re: [algogeeks] Amazon Question

2011-08-08 Thread Pradeep Mishra
i think for 3rd answer should be 1:1 correct me if m wrong. On Mon, Aug 8, 2011 at 7:42 AM, sagar pareek wrote: > 1. O(n) > 2. b > 4 c > > On Mon, Aug 8, 2011 at 8:08 PM, programming love < > love.for.programm...@gmail.com> wrote: > >> 1. O(n) >> 2.b >> 4.c >> >> >> On Mon, Aug 8, 2011 at 7:24

Re: [algogeeks] Amazon Question

2011-08-08 Thread sagar pareek
1. O(n) 2. b 4 c On Mon, Aug 8, 2011 at 8:08 PM, programming love < love.for.programm...@gmail.com> wrote: > 1. O(n) > 2.b > 4.c > > > On Mon, Aug 8, 2011 at 7:24 PM, ankit sambyal wrote: > >> Plz give the answers ... >> >> 1. In a binary max heap containing n numbers, the smallest element can b

Re: [algogeeks] Amazon Question

2011-08-08 Thread programming love
1. O(n) 2.b 4.c On Mon, Aug 8, 2011 at 7:24 PM, ankit sambyal wrote: > Plz give the answers ... > > 1. In a binary max heap containing n numbers, the smallest element can be > found in time ?? > > > 2. The number of total nodes in a complete balanced binary tree with n > levels is, > a)3^n + 1

Re: [algogeeks] Amazon Question

2011-08-08 Thread Gyanendra Kumar
i think for 3rd it shud be c.)1:1 On Mon, Aug 8, 2011 at 7:56 PM, rajeev bharshetty wrote: > 4) b > 3) a > > Correct me if i am wrong > > > On Mon, Aug 8, 2011 at 7:54 PM, Dipankar Patro wrote: > >> 1. O(n) >> >> 2. (b) >> >> >> >> On 8 August 2011 19:24, ankit sambyal wrote: >> >>> Plz give the

Re: [algogeeks] Amazon Question

2011-08-08 Thread rajeev bharshetty
4) b 3) a Correct me if i am wrong On Mon, Aug 8, 2011 at 7:54 PM, Dipankar Patro wrote: > 1. O(n) > > 2. (b) > > > > On 8 August 2011 19:24, ankit sambyal wrote: > >> Plz give the answers ... >> >> 1. In a binary max heap containing n numbers, the smallest element can be >> found in time ?? >

Re: [algogeeks] Amazon Question

2011-08-08 Thread Dipankar Patro
1. O(n) 2. (b) On 8 August 2011 19:24, ankit sambyal wrote: > Plz give the answers ... > > 1. In a binary max heap containing n numbers, the smallest element can be > found in time ?? > > > 2. The number of total nodes in a complete balanced binary tree with n > levels is, > a)3^n + 1 > b)

Re: [algogeeks] amazon question

2011-08-07 Thread Shachindra A C
8 one's and 8 two's. The order in which they get printed might vary. On Mon, Aug 8, 2011 at 11:11 AM, Kamakshii Aggarwal wrote: > what will be the o/p of the following program: > > main() > { > int ret; > ret=fork(); > ret=fork(); > ret=fork(); > ret=fork(); > > if(!ret) > printf("one"); > else >

Re: [algogeeks] Amazon Question

2011-08-05 Thread Arun Vishwanathan
hmm the problem is we need O(1) spacehaving that count wont make it O(1). i had an approach in mind of O(n) time and O(1) space..problem is i havent tested/debugged the code but it is O(1) space i guess and O(n) time. if total number of zeros(M) and 1s(N) are same print the whole array else

Re: [algogeeks] Amazon Question

2011-08-05 Thread surender sanke
Hi, for 1 do +1 for 0 do -1 maintain count at every index of array eg: 100110 array X 1 0 0 0 0 0 0 1 1 0 count 0 1 0 -1 -2 -3 -4 -5 -4 -3 -4 index -1 0 1 2 3 4 5 6 7 8 9 find count with same value having max index difference. -3 is count at index 4 and 8 max difference

Re: [algogeeks] Amazon Question

2011-08-05 Thread Arun Vishwanathan
by the way doesnt it look like an O(n^2) algo? On Fri, Aug 5, 2011 at 10:53 AM, Arun Vishwanathan wrote: > > would u mind giving a short explanation of yr code too if possible? > > > On Thu, Aug 4, 2011 at 5:38 PM, Apoorve Mohan wrote: > >> I think this should worktell me if this works... >> >

Re: [algogeeks] Amazon Question

2011-08-05 Thread Arun Vishwanathan
would u mind giving a short explanation of yr code too if possible? On Thu, Aug 4, 2011 at 5:38 PM, Apoorve Mohan wrote: > I think this should worktell me if this works... > > void longest_0_1_substring(char *str) > { > int size=0,count=0,max=0,pos=0,prev=0,prev_pos=0,ptr=0,i=0,j=0; > >

Re: [algogeeks] Amazon Question

2011-08-04 Thread Apoorve Mohan
I think this should worktell me if this works... void longest_0_1_substring(char *str) { int size=0,count=0,max=0,pos=0,prev=0,prev_pos=0,ptr=0,i=0,j=0; while(*str++) size++; str -= (size + 1); while(i 1) { if(count >= prev) {

Re: [algogeeks] Amazon Question

2011-08-04 Thread himanshu kansal
okie...can someone do it in O(n) space...bt time shld be linear only On Thu, Aug 4, 2011 at 2:13 AM, Prakash D wrote: > O(1) space is t hard for this task > > > On Thu, Aug 4, 2011 at 12:55 AM, payel roy wrote: > >> Is there any solution for the above? >> >> >> On 3 August 2011 21:09,

Re: [algogeeks] Amazon Question

2011-08-03 Thread Prakash D
O(1) space is t hard for this task On Thu, Aug 4, 2011 at 12:55 AM, payel roy wrote: > Is there any solution for the above? > > > On 3 August 2011 21:09, coder coder wrote: > >> ya amazon will be visiting our campus within few days >> >> -- >> You received this message because you are sub

Re: [algogeeks] Amazon Question

2011-08-03 Thread payel roy
Is there any solution for the above? On 3 August 2011 21:09, coder coder wrote: > ya amazon will be visiting our campus within few days > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@

Re: [algogeeks] Amazon Question

2011-08-03 Thread coder coder
ya amazon will be visiting our campus within few days -- 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...@google

Re: [algogeeks] Amazon Question

2011-08-03 Thread Kunal Patil
Sort both the lists... (Keep track of their original indices as we need to return to original list) Modify the merge process of merge_sort: // Assume size of list1 is m and that of list2 is n curr_list1=0;curr_list2=0;curr_output=0; while( curr_list1 < m && curr_list2 < n ) { If (list1[curr_l

Re: [algogeeks] Amazon Question

2011-08-03 Thread Nitin Nizhawan
EDIT: why not first sort the lists first? (we can create copy if we do not want to modify original list) it will give O(nLogn) solution -Nitin On Wed, Aug 3, 2011 at 4:59 PM, Nitin Nizhawan wrote: > why not first sort the lists first? (we could if we do not want to modify > original list) it wi

Re: [algogeeks] Amazon Question

2011-08-03 Thread Nitin Nizhawan
why not first sort the lists first? (we could if we do not want to modify original list) it will give O(nLogn) solution -Nitin On Wed, Aug 3, 2011 at 4:44 PM, veera reddy wrote: > sry... misunderstood the question > > > On Wed, Aug 3, 2011 at 4:43 PM, veera reddy wrote: > >> there is o(m+n) sol

Re: [algogeeks] Amazon Question

2011-08-03 Thread veera reddy
sry... misunderstood the question On Wed, Aug 3, 2011 at 4:43 PM, veera reddy wrote: > there is o(m+n) solution . > http://geeksforgeeks.org/?p=2405 in this link see method no 4 > > > On Wed, Aug 3, 2011 at 4:41 PM, ankit sambyal wrote: > >> ya, I also can't think anything better than O(m*n) >>

Re: [algogeeks] Amazon Question

2011-08-03 Thread veera reddy
there is o(m+n) solution . http://geeksforgeeks.org/?p=2405 in this link see method no 4 On Wed, Aug 3, 2011 at 4:41 PM, ankit sambyal wrote: > ya, I also can't think anything better than O(m*n) > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks

Re: [algogeeks] Amazon Question

2011-08-03 Thread ankit sambyal
ya, I also can't think anything better than O(m*n) -- 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...@googlegro

Re: [algogeeks] Amazon Question

2011-08-03 Thread Prakash D
someone post all the questions asked by amazon pls.. it'll be useful On Wed, Aug 3, 2011 at 3:43 PM, Arun Vishwanathan wrote: > it cud also be 0011 > > > On Wed, Aug 3, 2011 at 6:54 AM, payel roy wrote: > >> It is contiguous ...the answer will be 0110. >> >> >> On 2 August 2011 20:59, ankit samb

Re: [algogeeks] Amazon Question

2011-08-03 Thread UMESH KUMAR
Order would be O(m*n)... On Wed, Aug 3, 2011 at 4:01 AM, ankit sambyal wrote: > Given two lists write a function which returns a list which is the > intersection of the two lists.the original lists should remain same. > (Intersection - if first list is say,1,20 3,45 and second list is 3,

Re: [algogeeks] Amazon Question

2011-08-03 Thread Arun Vishwanathan
it cud also be 0011 On Wed, Aug 3, 2011 at 6:54 AM, payel roy wrote: > It is contiguous ...the answer will be 0110. > > > On 2 August 2011 20:59, ankit sambyal wrote: > >> @payel : Is it sub-sequence or sub-array ?? A sub-sequence may not be >> continuous but a sub-array must be continuous. eg

Re: [algogeeks] Amazon Question

2011-08-02 Thread payel roy
It is contiguous ...the answer will be 0110. On 2 August 2011 20:59, ankit sambyal wrote: > @payel : Is it sub-sequence or sub-array ?? A sub-sequence may not be > continuous but a sub-array must be continuous. eg : What wud be the answer > for- 100110 ?? > > -- > You received this message

Re: [algogeeks] Amazon Question

2011-08-02 Thread ankit sambyal
@payel : Is it sub-sequence or sub-array ?? A sub-sequence may not be continuous but a sub-array must be continuous. eg : What wud be the answer for- 100110 ?? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send

  1   2   >