[algogeeks] amazon question

2012-10-23 Thread saket
We have a long chain of cuboids in all the six directions (six faces). One start node is given and one end node is given. Give a data structure to represent this also search for the given node from start node. -- You received this message because you are subscribed to the Google Groups

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 narayan.shiv...@gmail.com wrote: We have a long chain of

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 bagana.bharatku...@gmail.comwrote: we can represent in 3-D array .. what type of elements are those .. is there any special kind of formation among elements for

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:

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 http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/ On Fri, Mar 23,

[algogeeks] Amazon question

2012-03-21 Thread amrit harry
hi i found this qstn frum career cup pls help to solve this. Given an integer n, compute 2 integers x, y satisfying: n=x*y=n+2; |x-y| is minimal. Thanks Regards Amrit -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion

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

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 drizzle...@gmail.com wrote: One possible way is: 1) Put the three candidate number together into an array

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 anika.jai...@gmail.com wrote: its coming out be either 1 or 2 in all cases

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 surend...@gmail.comwrote: @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

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 usrivastav...@gmail.comwrote: @Surinder give some proof or logic On Sun, Nov 13, 2011 at 10:25 AM, surender sanke surend...@gmail.comwrote: @nitin yes i meant the same, if each different

[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

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 thesnoop...@gmail.com wrote: Given a string consisting of a,b and c's, we can perform the following operation:

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 surend...@gmail.com wrote: All distinct combinations

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 surend...@gmail.com 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

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 nitin.garg.i...@gmail.comwrote: 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

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;istr.size();i++){ if(str[i]==str[j]){ j++; } else if(str[j]!=str[i]){

Re: [algogeeks] Amazon Question

2011-11-12 Thread Srinivasa Chaitanya T
On Sat, Nov 12, 2011 at 4:24 PM, Snoopy Me thesnoop...@gmail.com 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

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 thesnoop...@gmail.com wrote:

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 ankurga...@gmail.com wrote: @Srinivas Wat if the string is abc then it

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

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

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

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]http://en.wikipedia.org/wiki/Pythagorean_triple#cite_note-0 is a fundamental formula for

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 shashank7andr...@gmail.comwrote: @wladimir , its PPT (Pythagoras triplets ) but its number theory based approach

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

2011-10-16 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 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-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

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 rahul.deshmukhpa...@gmail.comwrote: 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

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 ankurga...@gmail.com wrote: @Rahul Pls elaborate with an example ... On Fri, Oct 14, 2011 at

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 ankurga...@gmail.com wrote: @Rahul Pls elaborate with an example ...

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 ankurga...@gmail.com 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

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 ankurga...@gmail.com wrote: @Rahul Pls elaborate with an example ... On Fri, Oct 14,

[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

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 - 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 ravindra.it...@gmail.com 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

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 ankurga...@gmail.com wrote: Dude this is nothing but 3 sum problem http://en.wikipedia.org/wiki/3SUM Ask interviewer to

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 ravindra.it...@gmail.comwrote: Hi, Another question I faced in Amazon F2F. Given an

[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

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 pawanjalsa.t...@gmail.com 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

[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 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 ankurga...@gmail.com 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

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

[algogeeks] Amazon question SDE

2011-09-20 Thread saurabh agrawal
Design an algorithm to perform operation on an array Add(i,y)- add value y to i position sum(i) - sum of first i numbers we can use additional array O(n) and worst case performance should be O(log n) for both operation -- You received this message because you are subscribed to the Google Groups

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

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

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 medu...@gmail.com wrote: @saurabh: i think may be u left some part of question to mention... the array may be a heap array ... or

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, *$* gopi.komand...@gmail.com wrote: How to find duplicate element (only one element is repeated) from an array of unsorted positive

Re: [algogeeks] Amazon question

2011-08-20 Thread Naren s
On Sat, Aug 20, 2011 at 9:07 PM, Naren s sweetna...@gmail.com 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, *$* gopi.komand...@gmail.com wrote: How to find

[algogeeks] Amazon Question

2011-08-18 Thread Ankur Garg
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 suggestions /solutions for this problem Regards Ankur -- You received this

Re: [algogeeks] Amazon Question

2011-08-18 Thread sagar pareek
Hashing :) On Thu, Aug 18, 2011 at 5:30 PM, Ankur Garg ankurga...@gmail.com 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.

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 sagarpar...@gmail.com wrote: Hashing :) On Thu, Aug 18, 2011 at 5:30 PM, Ankur Garg ankurga...@gmail.com wrote: Define a data structure , using extra memory/space , such that : Insert(int a) Delete(int a)

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 ankurga...@gmail.com wrote: Define a data structure , using extra memory/space , such that : Insert(int a) Delete(int a) isPresent(int a) get(int a) All

Re: [algogeeks] Amazon Question

2011-08-18 Thread Anantha Krishnan
Refer here http://ideone.com/X77wm. On Thu, Aug 18, 2011 at 5:36 PM, Ankur Garg ankurga...@gmail.com wrote: Can u provide a bit detail bro !! On Thu, Aug 18, 2011 at 8:04 AM, sagar pareek sagarpar...@gmail.comwrote: Hashing :) On Thu, Aug 18, 2011 at 5:30 PM, Ankur Garg

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 ankurga...@gmail.com wrote: Can u provide a bit detail bro !! On Thu, Aug 18, 2011 at 8:04 AM, sagar pareek sagarpar...@gmail.comwrote:

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] Amazon question

2011-08-18 Thread *$*
How to find duplicate element (only one element is repeated) from an array of unsorted positive integers.. time complexity .. O(n) space .. o(1). -- 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 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, send

[algogeeks] amazon question

2011-08-15 Thread priya ramesh
You are given a dictionary of all valid words. You have the following 3 operations permitted on a word: delete a character, insert a character, replace a character. Now given two words - word1 and word2 - find the minimum number of steps required to convert word1 to word2. (one operation counts as

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

[algogeeks] Amazon question.

2011-08-09 Thread Samba Ganapavarapu
We have an array of integers, we need to find the element a[i],a[j] and a[k] values where.. a[i]^2 + a[k]^2 = a[k] ^2 what would be the fast algorithm to find ? - Samba -- 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-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(jk) { if(a[[i] + a[j] == a[k]) printf(\n%d %d %d,sqrt(a[i]),sqrt(a[j]),sqrt(a[k])); else if(a[i] + a[j] a[k]) j++;

Re: [algogeeks] Amazon question.

2011-08-09 Thread programming love
*Executing code with printf's for each iteration for better understanding.* #includestdio.h 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; in; i++){ scanf(%d, a[i]); } for(i=0; in; i++) a[i]=a[i]*a[i]; k=n-1; i=0; j=k;

[algogeeks] Amazon Question

2011-08-08 Thread ankit sambyal
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)2^(n+1) - 1 c) 2^n + 1 d) none of above 3. In a country where everyone wants

Re: [algogeeks] Amazon Question

2011-08-08 Thread Dipankar Patro
1. O(n) 2. (b) On 8 August 2011 19:24, ankit sambyal ankitsamb...@gmail.com 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,

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 dip10c...@gmail.com wrote: 1. O(n) 2. (b) On 8 August 2011 19:24, ankit sambyal ankitsamb...@gmail.com wrote: Plz give the answers ... 1. In a binary max heap containing n numbers, the smallest element

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 rajeevr...@gmail.comwrote: 4) b 3) a Correct me if i am wrong On Mon, Aug 8, 2011 at 7:54 PM, Dipankar Patro dip10c...@gmail.comwrote: 1. O(n) 2. (b) On 8 August 2011 19:24, ankit sambyal

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 ankitsamb...@gmail.comwrote: 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,

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 ankitsamb...@gmail.comwrote: Plz give the answers ... 1. In a binary max heap containing n numbers, the smallest

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 sagarpar...@gmail.com 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 Brijesh Upadhyay
Yeah.. 3rd answer is 1:1 , for reference http://discuss.fogcreek.com/techInterview/default.asp?cmd=showixPost=150 -- 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] 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 sagarpar...@gmail.com 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 ankitsamb...@gmail.comwrote:

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 gyanendra.ii...@gmail.com wrote: i think for 3rd it shud be c.)1:1 On Mon, Aug 8, 2011 at 7:56 PM, rajeev bharshetty rajeevr...@gmail.comwrote: 4) b

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

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 rajuljain...@gmail.com 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 Kamakshii Aggarwal
3? On Mon, Aug 8, 2011 at 11:26 PM, siddharam suresh siddharam@gmail.comwrote: is it 3 ? Thank you, Siddharam On Mon, Aug 8, 2011 at 11:24 PM, rajul jain rajuljain...@gmail.comwrote: How many Children process following program produce * void main() { int p1= fork();

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 siddharam@gmail.comwrote: is it 3 ? Thank you, Siddharam On Mon, Aug 8, 2011 at 11:24 PM, rajul jain rajuljain...@gmail.comwrote: How many Children process following program produce * void

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

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 ankitsamb...@gmail.comwrote: @aditi : the ans is 3. Why do u think there is no definite ans ? --

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
@sagar: Thanx a lot On Tue, Aug 9, 2011 at 12:15 AM, sagar pareek sagarpar...@gmail.com wrote: * void main() { int p1= fork(); if (p1 == 0) { int p2 = fork(); if (p2 != 0) { fork(); } } } for

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 aditi.garg.6...@gmail.comwrote: 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

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

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 visit

[algogeeks] amazon question

2011-08-07 Thread Kamakshii Aggarwal
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 printf(two); } -- Regards, Kamakshi kamakshi...@gmail.com -- You received this message because you are subscribed to the Google Groups Algorithm

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 kamakshi...@gmail.comwrote: 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);

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 apoorvemo...@gmail.comwrote: I think this should worktell me if this works... void longest_0_1_substring(char *str) { int

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 aaron.nar...@gmail.comwrote: would u mind giving a short explanation of yr code too if possible? On Thu, Aug 4, 2011 at 5:38 PM, Apoorve Mohan apoorvemo...@gmail.comwrote: I think this should

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
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-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 cegprak...@gmail.com wrote: O(1) space is t hard for this task On Thu, Aug 4, 2011 at 12:55 AM, payel roy smithpa...@gmail.com wrote: Is there any solution for the above?

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 smithpa...@gmail.com wrote: It is contiguous ...the answer will be 0110. On 2 August 2011 20:59, ankit sambyal ankitsamb...@gmail.com wrote: @payel : Is it sub-sequence or sub-array ?? A sub-sequence may not be continuous but

[algogeeks] Amazon Question

2011-08-03 Thread ankit sambyal
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,24 ,45,90,68 then intersection should be 3,45 ) -- You received this message because you are

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 ankitsamb...@gmail.comwrote: 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

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 aaron.nar...@gmail.comwrote: it cud also be 0011 On Wed, Aug 3, 2011 at 6:54 AM, payel roy smithpa...@gmail.com wrote: It is contiguous ...the answer will be 0110. On 2

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

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 ankitsamb...@gmail.comwrote: ya, I also can't think anything better than O(m*n) -- You received this message because you are subscribed to the Google Groups

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 veeracool...@gmail.com 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 ankitsamb...@gmail.comwrote: ya, I also can't

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 veeracool...@gmail.com wrote: sry... misunderstood the question On Wed, Aug 3, 2011 at 4:43 PM, veera reddy

  1   2   >