Re: [algogeeks] Facebook Question

2011-12-21 Thread Algoose chase
Find the distance between each of the points and the origin(0,0) and sort the points based on this distance. Also, divide the points based on which quadrant they belong. If the difference between their distance(from origin) between 2 points is less and they belong to the same quadrant, then they

Re: [algogeeks] Facebook Question

2011-12-21 Thread Algoose chase
Yup, it could be O(n^2) in the worst case. On Wed, Dec 21, 2011 at 1:59 PM, Carol Smith carol.interv...@gmail.comwrote: @Algoose, in worst case, this is still O(n^2), ain't it? On Wed, Dec 21, 2011 at 12:50 PM, Algoose chase harishp...@gmail.comwrote: Find the distance between each

Re: [algogeeks] Re: Interview question

2011-12-04 Thread Algoose chase
n = x%2 ? x can be any integer. On Fri, Dec 2, 2011 at 5:19 PM, Don dondod...@gmail.com wrote: (!x || !(x^1)) !(x1) !((x|1)-1) (x*x)==x (x==(x==x))||(x==(x!=x)) etc. On Nov 29, 9:07 pm, Nitin Garg nitin.garg.i...@gmail.com wrote: *What are the different ways to say, the value of x

Re: [algogeeks] Re: sort the array

2011-06-22 Thread Algoose chase
Reverse the 2nd part of the Array so that they are sorted in descending order. Then apply bitonic sort On Wed, Jun 22, 2011 at 2:34 PM, ross jagadish1...@gmail.com wrote: @himanshu: I dont think, the approach works, in present form. in place merge sort or insertion sort is fine. Test with,

Re: [algogeeks] Re: Scheduling

2011-06-11 Thread Algoose chase
Will this work ? Order by choosing the last element of the permutation first. initially Calculate T = Total time of all tasks and calculate for all i, (T-Ti)*Ci and choose the task with min among them as last. To find the next last element , re-calculate T = T-Ti(i being the element chosen in

Re: [algogeeks] Re: BST+Heap

2011-06-11 Thread Algoose chase
1. Insert the node(order of insertion is irrelevant) in any order according to the binary search tree properties. 2. Compare the j value of node with its parent recursively (bottom up) and then perform rotations to restore the Heap property. On Thu, Jun 9, 2011 at 12:38 AM, mukesh tiwari

Re: [algogeeks] SPOJ PROBLEM

2011-03-15 Thread Algoose chase
, Mar 9, 2011 at 5:10 PM, Algoose chase harishp...@gmail.comwrote: Hi, Any solution other than brute force(exponential growth) for this problem ? On Sun, Mar 6, 2011 at 6:42 PM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: can anyone please tell me why i am getting wrong answer

Re: [algogeeks] SPOJ PROBLEM

2011-03-09 Thread Algoose chase
Hi, Any solution other than brute force(exponential growth) for this problem ? On Sun, Mar 6, 2011 at 6:42 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: can anyone please tell me why i am getting wrong answer for problem.https://www.spoj.pl/problems/TRT/ . . . MY CODE IS THIS

Re: [algogeeks] Re: Byte or Bite...Its byte Array

2011-02-22 Thread Algoose chase
@Jammy in case of 1X Since X is the start of a character, thus the preceding byte couldn't the first byte of the 2-byte character.. So the MSb of the byte preceding X must be a dont care. So in that case shouldn't we delete 2 bytes preceding X ? On Thu, Feb 17, 2011 at 12:20 AM, bittu

Re: [algogeeks] Directory Structure

2011-02-22 Thread Algoose chase
I think we can build a n-ary tree from the n directory paths that are already available in the computer and then for each of the m directory paths we can traverse the tree up until the directory which is already available in the tree and then count the remaining directories in the path. 1

Re: [algogeeks] Re: top search queries

2011-02-04 Thread Algoose chase
of n lesser the error proneness. On Thu, Feb 3, 2011 at 9:51 PM, Srikar srikar2...@gmail.com wrote: @algoose I see what you are saying. what do you propose? checking out your link now... On Thu, Feb 3, 2011 at 11:44 AM, Algoose chase harishp...@gmail.comwrote: @Srikar In your first

Re: [algogeeks] Re: top search queries

2011-02-03 Thread Algoose chase
@Srikar In your first approach you cant simply ignore the queries that are not present in the heap because you have a stream of queries and you never know if the query that you are about to ignore is going be received frequently or not in future. Your approach is like find the top 100 queries

Re: [algogeeks] number of brackets

2011-01-31 Thread Algoose chase
The DP solution to this problem is very similar DP solution for counting the number of Dyck words with some additional conditions. while calculating DP[i][j] you need to check if i+j equals one from the list of k values. if yes copy the value from the prev row(i.e DP[i-1][j]) instead of

Re: [algogeeks] Re: Amazon Question

2011-01-26 Thread Algoose chase
@ritu how would you find a successor without extra space if you dont have a parent pointer ? for Instance from the right most node of left subtree to the parent of left subtree(root) ? @Juver++ Internal stack does count as extra space !! On Wed, Jan 26, 2011 at 3:02 PM, ritu

Re: [algogeeks] Re: Amazon Question

2011-01-26 Thread Algoose chase
26, 2011 at 3:27 PM, Algoose chase harishp...@gmail.comwrote: @ritu how would you find a successor without extra space if you dont have a parent pointer ? for Instance from the right most node of left subtree to the parent of left subtree(root) ? @Juver++ Internal stack does count as extra

Re: [algogeeks] Re: Amazon Question

2011-01-24 Thread Algoose chase
If we shouldn't use recursion at it uses internal stack, then I hope we can use Morris tree traversal and use a counter to find the 5th max. On Fri, Jan 21, 2011 at 11:19 PM, juver++ avpostni...@gmail.com wrote: @above yes, posted solution needs parent links. Another solution is to process

Re: [algogeeks] Distance in a dictionary

2011-01-22 Thread Algoose chase
To add to what nishaanth mentioned, I think we should also track all the state transitions so that we can back track and make alternate transitions if the path that was already taken was later found to be incorrect one which will not help to reach the given target (with the given set of words).

Re: [algogeeks] Re: Google Question

2011-01-21 Thread Algoose chase
hope this works : #includestdio.h #define MAX(A,B) AB?A:B #defineMIN(A,B) AB?A:B int FindMaxA(int n) { int i,k,factor,max = 0,cur,prev; int* arr = new int[n+1]; int p = MIN(n,4); for( int j = 1;j = p;j++) arr[j] = j; for(i=5;i=n;i++) { k = i-4;

Re: [algogeeks] Re: amazon c questn

2011-01-18 Thread Algoose chase
@avpostnikov In my reply I meant TCHAR ( maybe it doesnt apply to the example given in the problem) when your project is being compiled as Unicode, the TCHAR would translate to wchar_t. If it is being compiled as ANSI/MBCS, it would translated to char Not always we explicitly use wchar_t. On

Re: [algogeeks] Re: google mcqs

2011-01-18 Thread Algoose chase
Pipeline : Choice B : 165 ( this pipeline wastes 20 ns between last 2 stages for each item ) Scheduling : Choice B Ram : Choice B Synchronization : Choice B On Mon, Jan 17, 2011 at 10:01 AM, Bhavesh agrawal agr.bhav...@gmail.comwrote: On Mon, Jan 17, 2011 at 10:00 AM, Bhavesh agrawal

Re: [algogeeks] Re: amazon c questn

2011-01-13 Thread Algoose chase
Apart from that , In Unicode application each char would be 2 bytes in length and its always advisable to use malloc(sizeof(char) * 25) which seamlessly works fine in ASCII application as well. On Wed, Jan 12, 2011 at 7:20 AM, Kiran K kira...@gmail.com wrote: p= (char*)malloc(25); KK: p

Re: [algogeeks] Re: Amazon Intrerview

2011-01-09 Thread Algoose chase
@Juver++ I am not sure if your input represents a path as asked in the problem. We typically think of a path within a binary tree as a downward path(from root to a leaf) thats not spread across different branches. Of course, if you consider that example as a valid case, then DFS wont work ! On

Re: [algogeeks] Re: Amazon Intrerview

2011-01-08 Thread Algoose chase
Will this work ? Find the node x, then the node y within the sub tree rooted at x and then z within the sub tree rooted at y since they must within a unique path If any of those searches fails there are no such nodes On Sun, Jan 9, 2011 at 6:02 AM, Gene gene.ress...@gmail.com wrote: The

Re: [algogeeks] Re: FINDSR in spoj

2010-12-21 Thread Algoose chase
Brute force : Have 2 pointers one pointing to last character and other pointing to the first occurrence of last character. compare the chars at the corresponding positions and decrement both pointers. when the latter hits -1 increment the counter and reset it to its original value. if the

Re: [algogeeks] Re: Max Heap + Binary Search Tree

2010-12-16 Thread Algoose chase
To insert a node into a tree with such a property: First insert the node into the tree using the rules of Binary Search tree based on Value i . Now compare Node-j and Node-Parent-j. Depending upon the result of comparison perform left rotation or right rotation so that the Heap property is also

Re: [algogeeks] Re: Maximum subarray whose sum is zero

2010-12-02 Thread Algoose chase
I believe the space complexity should be O(n) since you need to store the cumulative sum corresponding to each of the elements from the input starting from the first element. On Wed, Dec 1, 2010 at 12:04 AM, Prims topcode...@gmail.com wrote: I got the solution to use a hash table storing

Re: [algogeeks] Dynamic prog.

2010-11-30 Thread Algoose chase
://tech-queries.blogspot.com/ On Thu, Nov 25, 2010 at 11:18 AM, Algoose chase harishp...@gmail.comwrote: For this specific case since only 2 operators are used : + , * and we know that * is the operator that maximizes the value(provided both the operands are not equal to one / none

Re: [algogeeks] sorting variant

2010-11-12 Thread Algoose chase
I am not sure if this what you are looking for. Assuming that the arrays are sorted in ascending order. Choose one of the 2 arrays as a Reference Array. for each element element in reference array, do a binary search to find all elements that are less than the current element in reference and

Re: [algogeeks] Re: Addition Of numbers in SLL

2010-08-17 Thread Algoose chase
The Solution is pretty straight forward when you long number is represented in reverse order in linked list. If the number is not in reverse order, We need an Explicit stack or we must Use Recursion . Other way around this is to construct another parallel linked list along with Sum(linked list)

Re: [algogeeks] minimum window containing charecters

2010-08-11 Thread Algoose chase
@ Anand, No , It doesnt Try with String2 = LH String1 = HELLO. I think LCS solves a different problem from the one being asked here. I think we must generate all possible combination of strings and for each combination , check if all chars from str2 is present in it. On Sun, Aug 1, 2010 at

Re: [algogeeks] algorithm

2010-07-26 Thread Algoose chase
Add Each number from the stream to a Doubly linked list in sorted fashion i = 1; j = 1; while( stream not empty) { if( i == 1 j == 1) { Median = Cur ; /*Create New list with ist Number*/ } Add_Node_In_Sorted_Order(Cur); If( If new node is added

Re: [algogeeks] You have 2 arrays of integer. You have to write a function, which take an integer as input and returns bool. Example array 1 has {1,5,10} array 2 has {2,5,9}. Func(3) should return t

2010-07-24 Thread Algoose chase
@jalaj TRY A:16, 12, 10, 6 ,2 B:11, 10,7, 2, 1 num: 26 On Sat, Jul 24, 2010 at 5:13 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: Take two pointers both at the start of each array... i=0,j=0 let the size of sorted arrays be m and n int func(int num,int m,int n){ int i=0,j=0;

Re: [algogeeks] Boxes!!!

2010-07-21 Thread Algoose chase
can we sort the boxes based on their volume in descending order and start highest volume box to lowest volume box (outer loop) -Inner loop start from lowest volume box to highest volume box upto the box considered in outer loop. Running time : O(n^2) On Tue, Jul 20, 2010 at 8:28 PM,

Re: [algogeeks] Re: center of a tree

2010-07-05 Thread Algoose chase
Given the collection of nodes that constitute the diameter of the tree, The node with Max height among them i.e the node thats closest to the root(top level node) need not necessarily have children with equal height. For Instance: If the the top_level_node-left-height

Re: [algogeeks] sum to 0

2010-06-16 Thread Algoose Chase
@ Amir: I think you cannot find two numbers in B and C such that their sum is -A[k] in O(n) in all cases with the logic that you mentioned. for instance you can try with : A : 2 7 8 10 B :-2, 0, 1, 9 C: -7 -2 1 3 On Wed, Jun 16, 2010 at 5:56 AM, Amir hossein Shahriari

Re: [algogeeks] isomorphic trees

2010-06-09 Thread Algoose Chase
The Definition of isomorphic trees given in the first post is incomplete We say two rooted unordered trees are isomorphic if 1. a tree with a single node (the root) is only isomorphic to a tree with a single node; 2. two trees with roots A and B, none of which is a single-node tree, are isomorphic

Re: [algogeeks] Single ordered list

2010-06-09 Thread Algoose Chase
For multiple ordered lists you can build a single Max heap out of elements from all this list and Process as its done in heapsort On Wed, Jun 9, 2010 at 9:14 PM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: I had answered this question(of multiple lists) 2 or three days back. Go into the

Re: [algogeeks] Removing extra parentheses in an infix string

2010-06-04 Thread Algoose Chase
Hi , To add to your logic, I hope we must also be checking at the precedence of the first operator that appears after the closing parenthesis ')' before we can decided if the parenthesis can be removed or not . On Thu, Jun 3, 2010 at 11:37 PM, Antony Vincent Pandian.S. sant...@gmail.com wrote:

Re: [algogeeks] Removing extra parentheses in an infix string

2010-06-03 Thread Algoose Chase
Will this work ? consider A+(B*C) have an operator stack to hold the operators. As we scan elements from left to right,push the operators in operator stack. when you encounter a '(' , then scan to find the first operator that comes after '(' (in this case *). If this operator has a higher

Re: [algogeeks] Removing extra parentheses in an infix string

2010-06-03 Thread Algoose Chase
Thats right !!! On Thu, Jun 3, 2010 at 6:08 PM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: So there is a prob algoose A*(B*C) and a*(b*c+d) i hope you understood -- -- Rohit Saraf Second Year Undergraduate, Dept. of Computer

Re: [algogeeks] Convert a Binary tree into spike.

2010-05-15 Thread Algoose Chase
Hi , We can do Breadth first search but without any additional Memory like Queue. Since we connect the siblings we can traverse through siblings. Going from Top to bottom, Each Internal node(non-leaf) must connect its children. If that internal node has a right sibling then connect the right most

Re: [algogeeks] a google question

2010-05-02 Thread Algoose Chase
...@gmail.com wrote: @Algoose Chase point taken Thanks Mohit Ranjan Samsung India Software Operations. On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.comwrote: @mohit The idea of DP is fine. When you find the Max i dont think you need to include A[i+1]+B[j+1] because

Re: [algogeeks] a google question

2010-05-02 Thread Algoose Chase
OOPs.. sorry this doesnt work ! On Sun, May 2, 2010 at 6:11 PM, Algoose Chase harishp...@gmail.com wrote: Hi will this work ? since we need Set S with n pairs of largest values , any such pair within the set would (always) contain A[0] or B[0] because they maximize the value of the pair

Re: [algogeeks] a google question

2010-05-01 Thread Algoose Chase
@mohit The idea of DP is fine. When you find the Max i dont think you need to include A[i+1]+B[j+1] because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] since both the lists are sorted in decreasing order. On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-29 Thread Algoose Chase
Hi, How do you define without extra space ? Doing any order traversal either using recursion or using iteration is going to take extra space . If you are given a binary tree represented by pointers that points to children nodes is it possible to do a heap sort without an array ? On Thu, Apr 29,

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-29 Thread Algoose Chase
; root-data = temp; BinarytoBST(NodeR); } On Thu, Apr 29, 2010 at 11:23 AM, Algoose Chase harishp...@gmail.comwrote: Hi, How do you define without extra space ? Doing any order traversal either using recursion or using

Re: [algogeeks] The Mystery Spiral

2010-04-27 Thread Algoose Chase
I have a logical question about the solution pasted. The Problem says given N*N numbers filled in a matrix , print the numbers in spiral . What the code does is it fills the N*N numbers in spiral in decreasing order and then prints the matrix contents left to right , top to bottom. Will the two

Re: [algogeeks] Re: Largest span of Increasing Pair in an array

2010-03-25 Thread Algoose Chase
Hi all, How about this ? set K to the first element i.e Array[0] and set j to the last element i.e Array[size-1]. Decrement the index j until you find Array[j] Array[j+1] and increment the index k until you find Array[k] Array[k-1] and do this until you find the conditions met. Does it solve

Re: [algogeeks] Re: Merge two BST in O(n) time with O(1)

2010-02-12 Thread Algoose Chase
Hi, @Asish meena and Arun : I dont think you can simply append a whole tree( BST2) at some position just because the root of the BST2 is at its correct position.For instance , Lets say you append BST2's Root anywhere within the left subtree of BST1's Root. But if the right most leaf node

Re: [algogeeks] string ques

2010-02-03 Thread Algoose Chase
:03 AM, Algoose Chase harishp...@gmail.comwrote: Hope you meant a pattern is sub-array containing 2 or more UNIQUE chars. hope based on dfn, abcd is also a pattern in the input you have given. On Tue, Feb 2, 2010 at 1:11 AM, ankit mahendru ankit.mahend...@gmail.com wrote: Q. Find all

Re: [algogeeks] string ques

2010-02-01 Thread Algoose Chase
Hope you meant a pattern is sub-array containing 2 or more UNIQUE chars. hope based on dfn, abcd is also a pattern in the input you have given. On Tue, Feb 2, 2010 at 1:11 AM, ankit mahendru ankit.mahend...@gmail.comwrote: Q. Find all the patterns once which are present in the character array

Re: [algogeeks] Add 2 long integers with digits represented by linked lists

2010-02-01 Thread Algoose Chase
PM, Algoose Chase harishp...@gmail.com wrote: Condition: Can we do it keeping the original lists intact ? ie without reversing it. I mean , No recursion no Reversing ... is it possible ? @kumar : 15234 is represented as 1-5-2-3-4 On Wed, Jan 27, 2010 at 4:09 PM, saurabh gupta

[algogeeks] Add 2 long integers with digits represented by linked lists

2010-01-26 Thread Algoose Chase
conditions: NO extra memory (@ stack or Heap) at all. No recursion. Any body has got any hint about how to get this done ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To

Re: [algogeeks] Algorithm for vector problem

2009-11-24 Thread Algoose Chase
void PrintFamilyTree(const short generation) { printf(Name : %s Generation = %d\n, m_Name.c_str(),generation); vectorHuman*::iterator it; for (it = this.begin(); it this.end() ;it++) { it-PrintFamilyTree(generation+1); } } On Tue, Nov 24, 2009 at 9:20 PM, Aditya Shankar

Re: [algogeeks] Re: Print binary tree in spiral

2009-11-23 Thread Algoose Chase
I posted this long b4 but dint see this error : Delivery to the following recipient failed permanently: algogeeks@googlegroups.com re-posting: BST_Spiral(struct node* root) { ht = Height(root); for( i = 0; i= ht; i++) { PrintSpiral(root, i, i%2 /*flip 1 and 0 alternately on each