Re: [algogeeks] interview quest..

2011-02-06 Thread ramkumar santhanam
use stack. -- 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, visit this

[algogeeks] Microsoft

2011-02-06 Thread Decipher
Algorithm to find the two numbers whose difference is minimum among the set of numbers. For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19 The algorithm should return min diff = 20-19 = 1. Constraint - Time Complexity O(N) Space is not a constraint [upto O(3N)] -- You

Re: [algogeeks] Microsoft

2011-02-06 Thread Abhijit K Rao
How about , using a sorting algorithm like Quick sort and return diff of last and the before last element. Best Regards Abhijit On Sun, Feb 6, 2011 at 3:29 PM, Decipher ankurseth...@gmail.com wrote: Algorithm to find the two numbers whose difference is minimum among the set of numbers.

[algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread algoseeker
I also encountered this question yesterday. This is my solution which i tested for a few sample cases. https://github.com/algoseeker/Interview/blob/master/Node.java I maintained a pointer to the Node where there should be creation of a new node. If the node created is left child, shift the

Re: [algogeeks] Re: Good question

2011-02-06 Thread jaladhi dave
it has variable defined On Sun, Feb 6, 2011 at 7:47 AM, Venki venkatcollect...@gmail.com wrote: Hi Gajendra, See the following link http://geeksforgeeks.org/forum/topic/huwaei-interview-question-for-software-engineerdeveloper-2-5-years-about-cpuzzles#post-18725 On Feb 5, 7:28 pm, Gajendra

[algogeeks] Regarding Google recruiting

2011-02-06 Thread Umer Farooq
Hello, I have applied for fresh grad posts in Google. I have filled up their forms and uploaded the resume. Can anyone tell me how long do they take to process the resume and how long should I wait? -- Umer -- You received this message because you are subscribed to the Google Groups

[algogeeks] amazon question

2011-02-06 Thread jalaj jaiswal
Write a function to check whether the Binary Tree is mirror structure. True (A (B (C,D), E( F,G))) or (A (B (C)), D(E))) False (A (B)) or (A (B,C(D,E))) -- tree is represented in string form as given above With Regards, *Jalaj Jaiswal* (+919019947895) Final Year Undergraduate, IIIT ALLAHABAD

[algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread jalaj
use a stack for this { //let preorder traversal of a tree be in a array t for(i = t.length; i-1; i--){ if(t(i) == L){ stack.push(t[i]); }else{ leftChild = s.pop(); // will return null if stack is empty rightChild = s.pop(); // will return null if stack is empty node = new Node(leftChild,

Re: [algogeeks] Re: kurukshetra...

2011-02-06 Thread Balaji S
thanks.. -- balaji ;-) -- 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

Re: [algogeeks] Re: kurukshetra...

2011-02-06 Thread Manmeet Singh
test case : a = -1, b = - 1 Result : fight successfully challenged dave's problem. Method returned 1 while it shud have returned -1. On Sun, Feb 6, 2011 at 4:12 PM, Balaji S balaji.ceg...@gmail.com wrote: thanks.. -- balaji ;-) -- You received this message because you are subscribed

Re: [algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread Gajendra Dadheech
I gues jalaj's solun works perfect. Thanks and regards, Gajendra Dadheech On Sun, Feb 6, 2011 at 4:06 PM, jalaj jalaj.jaiswa...@gmail.com wrote: use a stack for this { //let preorder traversal of a tree be in a array t for(i = t.length; i-1; i--){ if(t(i) == L){ stack.push(t[i]);

[algogeeks] Re: amazon question

2011-02-06 Thread bittu
@jalal hi You Can Use This algorithm to construct the Mirror tree (1) Call Mirror for left-subtreei.e., Mirror(left-subtree) (2) Call Mirror for right-subtree i.e., Mirror(left-subtree) (3) Swap left and right subtrees. temp = left-subtree left-subtree = right-subtree

Re: [algogeeks] interview quest..

2011-02-06 Thread Abhijit K Rao
I could not get it for recursively, but iteratively, I coded a solution. If anyone knows recursively, let us know please. #includestdio.h void main() { char s[18]=DGGDBCBHH; int i=0,j=0; int count; while(s[i]!='\0') { if(s[i] == s[i+1]) {

Re: [algogeeks] Microsoft

2011-02-06 Thread coolfrog$
@Decipher Microsoft is coming in over college.. can you Give some more question which are recently asked ...in MS test... @everone.. do share question of MS if some body has given the recently this Test.. Algorithm: 1. maintain min_diff so far 2. maintain max_element so far complexity is O(n) ,

Re: [algogeeks] Microsoft

2011-02-06 Thread Gajendra Dadheech
algo fails for following input set 20,18,1,7,2 Thanks and regards, Gajendra Dadheech On Sun, Feb 6, 2011 at 6:32 PM, coolfrog$ dixit.coolfrog.div...@gmail.comwrote: @Decipher Microsoft is coming in over college.. can you Give some more question which are recently asked ...in MS test...

Re: [algogeeks] Re: kurukshetra...

2011-02-06 Thread radha krishnan
that should be (a+b+abs(a-b))/2 On Sun, Feb 6, 2011 at 4:15 PM, Manmeet Singh mans.aus...@gmail.com wrote: test case : a = -1, b = - 1 Result : fight successfully challenged dave's problem. Method returned 1 while it shud have returned -1. On Sun, Feb 6, 2011 at 4:12 PM, Balaji S

Re: [algogeeks] Microsoft

2011-02-06 Thread radha krishnan
i use CountSort as i assuming maxn=20 :) and then find the adjacent diff of the sorted array to find the min On Sun, Feb 6, 2011 at 7:21 PM, Gajendra Dadheech gajju3...@gmail.com wrote: algo fails for following input set 20,18,1,7,2 Thanks and regards, Gajendra Dadheech On Sun, Feb 6,

Re: [algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread jalaj jaiswal
My solution in more detail (in words ):- start from the end if you get an L make a node with data L and push its pointer in stack, if you get a M pop two elements from stack make them left and right children of M and then push back m's pointer to stack(if stack is empty then stack returns NULL

[algogeeks] one more from amazon

2011-02-06 Thread Gajendra Dadheech
Write a function to print all unique partitions on n tht are of size m. eg: n=10, m=4. it should print 7 1 1 1, 6 2 1 1, 5 3 1 1, 3 3 2 2,, so on Thanks and regards, Gajendra Dadheech hi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Regarding Google recruiting

2011-02-06 Thread Amit Agarwal
Any idea about whats the probability of getting rejected by *Hiring* * Committee*? -Regards *Amit Agarwal http:///www.amitagrwal.com* +91-779-822-8765 On Sun, Feb 6, 2011 at 8:38 PM, Badrinath Kulkarni urba...@gmail.comwrote:

[algogeeks] o/p

2011-02-06 Thread ranjane
what s the o/p of the followin pgm? main() { int i=300; char *ptr; ptr=i; *++ptr=2; printf(%d,i); } -- 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

Re: [algogeeks] o/p

2011-02-06 Thread Gajendra Dadheech
i think it will be 34... Thanks and regards, Gajendra Dadheech On Sun, Feb 6, 2011 at 10:15 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: @ranjane the value of i will not change as ++ptr will execute first. but i wonder if a char pointer can be used to store integer address... will

Re: [algogeeks] o/p

2011-02-06 Thread aditya pratap
i do'nt know why it is printing 556. could anyone give me the logic. Aditya Pratap MCA II Delhi University -- 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

Re: [algogeeks] o/p

2011-02-06 Thread jalaj jaiswal
@aditya which compiler are you using On Sun, Feb 6, 2011 at 10:21 PM, aditya pratap contacttoadity...@gmail.comwrote: i do'nt know why it is printing 556. could anyone give me the logic. Aditya Pratap MCA II Delhi University -- You received this message because you are subscribed to

[algogeeks] Re: first larger element in unsorted array...

2011-02-06 Thread Ralph Boland
On Jan 31, 11:17 am, ritu ritugarg.c...@gmail.com wrote: @Ralph Build a data structure on array B[1..n]  in O(n) time such that the following problem can be solved in O(log n) time:     Given an index i and value  v,  find the index j of the first     element in  B  such that  j = i and

Re: [algogeeks] o/p

2011-02-06 Thread aditya pratap
@jalaj : gcc compiler. -- 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,

Re: [algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread yq Zhang
but the tree can be created from a preorder walk is more than 1 right? so the question only ask for 1? On Feb 6, 2011 7:31 AM, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: My solution in more detail (in words ):- start from the end if you get an L make a node with data L and push its pointer

Re: [algogeeks] o/p

2011-02-06 Thread jalaj jaiswal
the logic is :- int is stored in 32 bits in our systems 300 is 0001 00101100 as ptr is character pointer, it points to lower 8 bits and when *++ptr=2 gets executed then 0001 changes to 0010(equal to 2) so i becomes 0010 00101100 which is 556 :D

Re: [algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread jalaj jaiswal
no unique tree will get created i think .. as first popped is left child and second popped is right child in algo On Sun, Feb 6, 2011 at 10:29 PM, yq Zhang zhangyunq...@gmail.com wrote: but the tree can be created from a preorder walk is more than 1 right? so the question only ask for 1? On

[algogeeks] array

2011-02-06 Thread jalaj jaiswal
Input: A unsorted array of size n. Output: An array of size n. Relationship: elements of input array and output array have 1:1 correspondence. output[i] is equal to the input[j] (ji) which is smaller than input[i] and jth is nearest to ith ( i.e. first element which is smaller). If no such

[algogeeks] Re: kurukshetra...

2011-02-06 Thread Dave
Both of you are right. Thanks for correcting my mistake. Dave On Feb 6, 8:10 am, radha krishnan radhakrishnance...@gmail.com wrote: that should be (a+b+abs(a-b))/2 On Sun, Feb 6, 2011 at 4:15 PM, Manmeet Singh mans.aus...@gmail.com wrote: test case : a = -1, b = - 1 Result : fight

Re: [algogeeks] Re: Good question

2011-02-06 Thread albert theboss
using this macro size(X) ((X*)0+1) if we give size(int) it ll return 4. size(double) gives 8. -- 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

[algogeeks] Re: array

2011-02-06 Thread jalaj jaiswal
got a O(n) soln guys Starts from an empty stack and scan the input array (IN) from the bottom (i = n-1): for(int i = n-1; i = 0; i--) { while (!stack.isEmpty() IN[i] = stack.top()) { stack.pop(); } if (stack.isEmpty()) { OUT[i] = 0; stack.add(IN[i]); continue; }

Re: [algogeeks] Re: Largest Rectangle in a binary Matrix:

2011-02-06 Thread Ashish Goel
how do we work for a rectangle here.. the only way i could think of is once we have found a square, backtrack from right bottom towards left and up to see if the value is not changing 10101 11100 1 11000 it will be 10101 11100 12211 12000 now here if (3,1) is considered, there there is a

[algogeeks] Tree problem(Amazon)

2011-02-06 Thread jalaj jaiswal
you are given a bst where each node has a int value , parent pointer , and left and right pointers , write a function to find a path with a given sum value. Path can go from left subtree tree , include root and go to right tree as well . we need to find these paths also . 5 / \ 110 / \/ \

[algogeeks] The C Programming Language, 2nd edition, Kernighan and Ritchie Solutions

2011-02-06 Thread priya mehta
Someone please share The C Programming Language, 2nd edition, Kernighan and Ritchie Solutions -- 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

Re: [algogeeks] one more from amazon

2011-02-06 Thread Wei.QI
public static ArrayListArrayListInteger Partition(int val, int start, int size) { ArrayListArrayListInteger r = new ArrayListArrayListInteger(); if (start * size val) { return null; } if(size == 1) { r.add(new ArrayListInteger()); r.get(0).add(val); return r; } for

Re: [algogeeks] one more from amazon

2011-02-06 Thread Sreeprasad Govindankutty
If duplicate values are allowed :: import java.io.BufferedReader; import java.io.InputStreamReader; public class PartionNumber { public static void main(String[] args) { System.out.println(Enter the number); InputStreamReader ifn = new InputStreamReader(System.in);

[algogeeks] language

2011-02-06 Thread Anand
There is a language with only two elements ie 'a' and 'bc'. How many words can be made out of it if whose Length is n. I think it is n+1. if the len = 3 abc bca if the len is 6 bc aaabca aabcaa abcaaa ba -- You received this message because you are subscribed to the Google Groups

[algogeeks] Mobile Operator

2011-02-06 Thread Anand
There is a firm that provides Mobile Operator 3 functions. 1. char[] get_number: to get a new number(10 digit) 2. bool is_allocated(char[]) : if the number is already allocated. 3. bool allocate(char[]) : allocate the number. What data structure to use? We can use hash table to store

[algogeeks] Amazon Interview question

2011-02-06 Thread may.I.answer
If [a1,a2,a3...,an,b1,b2...bn] is given input change this to [a1,b1,a2,b2.an,bn] -- 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

Re: [algogeeks] language

2011-02-06 Thread nphard nphard
For len = 6, isn't bcbcbc also valid? On Sun, Feb 6, 2011 at 9:08 PM, Anand anandut2...@gmail.com wrote: There is a language with only two elements ie 'a' and 'bc'. How many words can be made out of it if whose Length is n. I think it is n+1. if the len = 3 abc bca if the len is 6

Re: [algogeeks] language

2011-02-06 Thread Rajeev Kumar
certainly it is not n+1. for n=1, ans is 'a'.No other word can be formed. On Sun, Feb 6, 2011 at 7:10 PM, nphard nphard nphard.nph...@gmail.comwrote: For len = 6, isn't bcbcbc also valid? On Sun, Feb 6, 2011 at 9:08 PM, Anand anandut2...@gmail.com wrote: There is a language with only two

[algogeeks] Re: language

2011-02-06 Thread Dave
@Anand: Let N(k) be the number of strings of length k. Since you can make a string of length k by appending 'a' onto a string of length k-1 or by appending 'bc' onto a string of length k-2, it follows that N(k) = N(k-1) + N(k-2) Furthermore, there are no strings of length -1 and only one string

Re: [algogeeks] one more from amazon

2011-02-06 Thread Gajendra Dadheech
Can someone explain the logic behind this Thanks and regards, Gajendra Dadheech On Mon, Feb 7, 2011 at 7:10 AM, Sreeprasad Govindankutty sreeprasad...@gmail.com wrote: If duplicate values are allowed :: import java.io.BufferedReader; import java.io.InputStreamReader; public

Re: [algogeeks] Re: c programming question

2011-02-06 Thread jagannath prasad das
ya i also want the explaination of gcc compiler output...thanx in advance On Sun, Feb 6, 2011 at 10:13 AM, tech rascal techrascal...@gmail.comwrote: but can nybody explain why the output is coming like this on gcc compiler?? On Sun, Feb 6, 2011 at 10:04 AM, Manish Verma

Re: [algogeeks] Re: c programming question

2011-02-06 Thread Anand
int a=10,b; b=a++ + ++a; (Till here I think it is clear the value of a is 12 and b = 22) printf(%d,%d,%d,%d,b,a++,a,++a); (Evaluate from right to left. So ++a makes the value of a as 13, then a and then a++ which is post increment still makes a as 13) Now it try to display the value from left

Re: [algogeeks] Re: c programming question

2011-02-06 Thread jagannath prasad das
@anand:while printing post fix gave 13 but rest two why 14 On Mon, Feb 7, 2011 at 10:28 AM, Anand anandut2...@gmail.com wrote: int a=10,b; b=a++ + ++a; (Till here I think it is clear the value of a is 12 and b = 22) printf(%d,%d,%d,%d,b,a++,a,++a); (Evaluate from right to left. So ++a

Re: [algogeeks] Re: c programming question

2011-02-06 Thread Anand
a++ when it gets printed. it is 13 and now it gets increment to 14. So now if you print a it will 14. On Sun, Feb 6, 2011 at 9:04 PM, jagannath prasad das jpdasi...@gmail.comwrote: @anand:while printing post fix gave 13 but rest two why 14 On Mon, Feb 7, 2011 at 10:28 AM, Anand

Re: [algogeeks] Re: Good question

2011-02-06 Thread Rajiv Podar
Hi Try following code Suppose we need to find size of variable *obj* int size = (char*)(obj +1 ) - (char*)(obj); * *Thanks Regards, Ricky On Mon, Feb 7, 2011 at 12:19 AM, albert theboss alberttheb...@gmail.comwrote: using this macro size(X) ((X*)0+1) if we give size(int) it ll

Re: [algogeeks] Re: c programming question

2011-02-06 Thread jagannath prasad das
@juver:in f(a)+f(b) i guess f(a) is evaluated first because fucntion calls are evaluated from left to right On Mon, Feb 7, 2011 at 10:37 AM, Anand anandut2...@gmail.com wrote: a++ when it gets printed. it is 13 and now it gets increment to 14. So now if you print a it will 14. On Sun, Feb

Re: [algogeeks] Re: Good question

2011-02-06 Thread jagannath prasad das
@rajiv:i guess obj is a pointer here On Mon, Feb 7, 2011 at 10:51 AM, Rajiv Podar rajeevpo...@gmail.com wrote: Hi Try following code Suppose we need to find size of variable *obj* int size = (char*)(obj +1 ) - (char*)(obj); * *Thanks Regards, Ricky On Mon, Feb 7, 2011 at

Re: [algogeeks] Amazon Interview question

2011-02-06 Thread jalaj jaiswal
A very common interview question let the array be from 0 to 2n-1 now, every element of array has its initial position and final position.. start from beginning if the elemnt you r processing is the first half of array then f=i+i; else f=2*i-(2n-1); replace the elemnt at final position with the

[algogeeks] Re: Good question

2011-02-06 Thread Ricky
@jagan: that's true obj is a pointer to the data type for which size need to be calculated. On Feb 7, 10:38 am, jagannath prasad das jpdasi...@gmail.com wrote: @rajiv:i guess obj is a pointer here On Mon, Feb 7, 2011 at 10:51 AM, Rajiv Podar rajeevpo...@gmail.com wrote: Hi

[algogeeks] C++ Riddle

2011-02-06 Thread Ricky
write the program to add two numbers without using arithmetic and bit operation.. -- 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: C++ Riddle

2011-02-06 Thread Dave
@Ricky: if increment and decrement operators are not considered arithmetic, try int sum(int m, int n) { while( m 0 ) { m--; n++; } while( m 0 ) { m++; n--; } return n; } On Feb 6, 11:49 pm, Ricky rajeevpo...@gmail.com wrote: write

Re: [algogeeks] Re: C++ Riddle

2011-02-06 Thread jalaj jaiswal
try this let nos be m n char * p; p=m; int sum = (int)p[n] ; sum is m+n :) On Mon, Feb 7, 2011 at 11:41 AM, Dave dave_and_da...@juno.com wrote: @Ricky: if increment and decrement operators are not considered arithmetic, try int sum(int m, int n) { while( m 0 ) { m--;

Re: [algogeeks] Re: C++ Riddle

2011-02-06 Thread Rajiv Podar
@Dave: ++ and -- are arithmetic operations. @Jalaj: I agree with the above solution Thanks Regards, Rajiv Podar On Mon, Feb 7, 2011 at 11:47 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: try this let nos be m n char * p; p=m; int sum = (int)p[n] ; sum is m+n :) On Mon,

Re: [algogeeks] Re: C++ Riddle

2011-02-06 Thread jagannath prasad das
bit operation means what? On Mon, Feb 7, 2011 at 12:00 PM, Rajiv Podar rajeevpo...@gmail.com wrote: @Dave: ++ and -- are arithmetic operations. @Jalaj: I agree with the above solution Thanks Regards, Rajiv Podar On Mon, Feb 7, 2011 at 11:47 AM, jalaj jaiswal

Re: [algogeeks] Re: C++ Riddle

2011-02-06 Thread Rajiv Podar
for e.g. u can use operator. int a = 1; a = a 1; a become 2; Or u cannot use any , |, ^ operations. Thanks Regards, Rajiv Podar On Mon, Feb 7, 2011 at 12:33 PM, jagannath prasad das jpdasi...@gmail.comwrote: bit operation means what? On Mon, Feb 7, 2011 at 12:00 PM, Rajiv Podar

[algogeeks] Re: o/p

2011-02-06 Thread ranjane
thank u jalaj On Feb 6, 10:03 pm, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: the logic is :- int is stored in 32 bits in our systems 300 is 0001 00101100 as ptr is character pointer, it points to lower 8 bits and when *++ptr=2 gets executed then 0001 changes to