Re: [algogeeks] Re: Longest Palindrome

2011-01-03 Thread juver++
@Anand post correct algorithm. There is no simpler method to find longest palindrome in a linear time. To understand the algorithm you may be should know the Z algorithm cause main idea is the same. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] Re: Interview question amazon

2011-01-03 Thread juver++
Tree structure already have parent node link. Even we reconstruct the tree as linked list we are not allowed to achieve the goal. Path can be combined using non-contigious (created from inorder traversal) elements. The only solution is using DP with O(MAX_SUM_VALUE) extra space for each node.

Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-03 Thread juver++
Yes, you are right. Stack contains the following pair of elements - (Min, Element), where Min - minimum element among all elements in the stack below the current, Element - current element. When you add new element onto the stack, then you should push pair(min(stack.top().Min, Element),

[algogeeks] Re: probability

2011-01-03 Thread Dave
@Salil: The argument I was making is that A will choose to shoot at B rather than C on his first shot if both are standing, because doing so maximizes A's chances of survival. Perhaps we are using the notation P(A shoots at C) to mean different things. Dave On Jan 3, 12:24 am, Salil Joshi

Re: [algogeeks] Longest Palindrome

2011-01-03 Thread Rishi Agrawal
The blogsite referred is unavailable. On Fri, Dec 31, 2010 at 3:49 AM, Anand anandut2...@gmail.com wrote: http://anandtechblog.blogspot.com/2010/06/find-longest-palindromic-substring-in.html On Thu, Dec 30, 2010 at 1:10 PM, Aniket aniket...@gmail.com wrote: How do you find the longest

Re: [algogeeks] Re: probability

2011-01-03 Thread jai gupta
@Dave: Sorry It was a typo but for the probability figures, When C shoots B then if he is successful then A will shoot C Hence he must be unsuccessful and then if B is unsuccessful then A must will Kill B and then C must kill A if B is successful then C must kill B now Hence P(when C shoots at

[algogeeks] Please Explain

2011-01-03 Thread Aniket
#includeiostream using namespace std; const int a[]={1,2,3,4,5}; int b[a[2]]; int main(){return 0;} If the code is like above it is giving error in line 4; But if it is something like below it gives no error after compilation: #includeiostream using namespace std; const int a=3; int b[a]; int

[algogeeks] Re: Please Explain

2011-01-03 Thread sova.kuli...@gmail.com
The C++ compiler can only allocate an array with a size known at compile time. If you want to allocated a variable size piece of memory, use the new operator. http://stackoverflow.com/questions/4589463/initialize-array-size-from-another-array-value On Jan 3, 4:58 pm, Aniket aniket...@gmail.com

Re: [algogeeks] Re: Interview question amazon

2011-01-03 Thread rahul patil
On Mon, Jan 3, 2011 at 6:08 PM, juver++ avpostni...@gmail.com wrote: Tree structure already have parent node link. Even we reconstruct the tree as linked list we are not allowed to achieve Normal tree node does not contain link to its parent. I am not saying convert tree into linklist

Re: [algogeeks] Re: Interview question amazon

2011-01-03 Thread rahul patil
On Tue, Jan 4, 2011 at 8:13 AM, rahul patil rahul.deshmukhpa...@gmail.comwrote: On Mon, Jan 3, 2011 at 6:08 PM, juver++ avpostni...@gmail.com wrote: Tree structure already have parent node link. Even we reconstruct the tree as linked list we are not allowed to achieve Normal tree node

[algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-03 Thread sourav
@yq Zhang, To pop if you are going to pop all from first stack and push into the second stack, then does your operation remain constant time? Please note that we need constant time implementation for the 3 functions pop_front, push_rear and get_min(). Goint by your approach, not all of them are

Re: [algogeeks] Divide an array into two equal subsets

2011-01-03 Thread rahul patil
What if we sort array and place first n/4 and last n/4 elements in one subarray and other n/2 in the 2nd subarray. On Fri, Dec 31, 2010 at 4:08 AM, Anand anandut2...@gmail.com wrote: http://anandtechblog.blogspot.com/2010/07/partition-of-array.html On Thu, Dec 30, 2010 at 12:35 AM, vishal