Re: [algogeeks] Reverse

2011-06-30 Thread sagar pareek
Thanks On Wed, Jun 29, 2011 at 2:45 AM, aditya kumar aditya.kumar130...@gmail.comwrote: @sagar : it works perfectly fine. On Tue, Jun 28, 2011 at 3:29 PM, sagar pareek sagarpar...@gmail.comwrote: Check out my solution above :) Its reversing the string On Tue, Jun 28, 2011 at 1:56

Re: [algogeeks] Re: Amazon telephonic question

2011-06-30 Thread ankit sambyal
@bittu : In your first approach which u pointed out : What if the minimum element is poped out of the stack ?? We may have to search the whole stack to get the minimum element. O(n) in worst case In your second approach which u pointed out : If u use 2 stacks, consistency of 2 stacks in

Re: [algogeeks] linked list

2011-06-30 Thread Rohan Kalra
http://geeksforgeeks.org/?p=12000 -- 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/-/OnLux79bj3MJ. To post to this group, send email to

Re: [algogeeks] strange output

2011-06-30 Thread Jitendra singh
scanf returns no of integers it read,not the read integer. On 6/26/11, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: It breaks out correctly when test condition value is 0 i.e when value of t is 1 On Sat, Jun 25, 2011 at 4:41 PM, sunny agrawal sunny816.i...@gmail.comwrote: No,

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread sagar pareek
In TRIE , we can store nodes by characters. So it is very easy to search by names and hence their corresponding numbers :) . TRIE saves a lot memory coz it stares a character only once. LIKE :- if i want to save sagar with phone no. 123456789 then we store it in TRIE as : s-NULL | a-NULL |

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread sagar pareek
Sorry for the previous post it got a mistake here take a look again :- In TRIE , we can store nodes by characters. So it is very easy to search by names and hence their corresponding numbers :) . TRIE saves a lot memory coz it stares a character only once. LIKE :- if i want to save sagar

Re: [algogeeks] Backtracking!

2011-06-30 Thread Nitish Garg
Thanks for the link! -- 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/-/xHZEwuTNT2kJ. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread Navneet Gupta
I wonder why people have discarded the idea of Hash map here. Searching is obviously the most important task here and if we are to assume that names can be uniformly hashed over a table of 1000 rows with each row containing 1000 names each. Further optimization can be achieved by having names

Re: [algogeeks] Explain this.....

2011-06-30 Thread Abhi
Well, according to gnu standards, it's never safe to depend on the order of evaluation of the arguements passed to a function. So the output in the above case would vary from compiler to compiler Source: http://gcc.gnu.org/onlinedocs/gcc/Non_002dbugs.html read the second last point -- You

[algogeeks] Amazon Telephonic Interview Questions

2011-06-30 Thread vikas
1. write iterative program to find if a binary tree is binary search tree or not. 2. write iterative program to convert a binary tree into its mirror image. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web

Re: [algogeeks] Re: POWER CRISES :Spoj

2011-06-30 Thread harshit pahuja
@rizwaan u r ryt bt i want a O(n) soln .. whats say On Wed, Jun 29, 2011 at 2:55 PM, rizwan hudda rizwanhu...@gmail.com wrote: http://ideone.com/MSLXT The constraints are so less that you can brute force the solution..N100. My solution is O(N^3) On Thu, Jun 30, 2011 at

[algogeeks] Re: Amazon Telephonic Interview Questions

2011-06-30 Thread Gene
For 1. you need an in-order traversal. During the visit check to see that each successive key is non-decreasing. For 2. you need a post order traversal. During the visit swap the left and right child pointers. Now you can look up the standard algorithms for these traversals. On Jun 30, 3:34 

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread juver++
@samby You are wrong anyway. Main problem is to reduce memory while storing phone numbers. We have 1 million of phones, they have many common prefixes which can be addressed by trie. For storing names, you may use any data structure which is best for the particular problem. Key is name, and

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread juver++
@Navneet Please read problem again - it is about memory efficient storing. -- 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/-/-hsmsOgm2YUJ. To post to this

[algogeeks] Re: Amazon Telephonic Interview Questions

2011-06-30 Thread vikas
for 1 i did implement exactly the same algorithms. and for 2 i donot know why but at that time i was not able to implement it iteratively and hense implemented its recursive version only. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Reverse

2011-06-30 Thread hary rathor
guy can anybody reverse without taking 0 extra variables ? -- 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] Reverse

2011-06-30 Thread juver++
We need at least one variable - loop counter. All other can be done via XOR. -- 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/-/AzSS4tMoDlYJ. To post to this

Re: [algogeeks] Reverse

2011-06-30 Thread hary rathor
@ juver++ : that i have already done. -- 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

Re: [algogeeks] Reverse

2011-06-30 Thread Anders Ma
On Tue, Jun 28, 2011 at 3:04 PM, sagar pareek sagarpar...@gmail.com wrote: I have 1 more solution :- #includestdio.h #includestring.h main() {  int i,j,l;  char arr[100];  printf(Enter the string\n);  fgets(arr,100,stdin);  for(i=0,l=strlen(arr),j=l;i=l/2;i++)  {   arr[j--]=arr[i];

Re: [algogeeks] Re: Amazon Telephonic Interview Questions

2011-06-30 Thread Anantha Krishnan
1. check here http://ideone.com/VjjqN *int isBSTiterative(Tnode *root) {* *int prev = -9;* *Tnode *node = NULL;* *while (root) {* *push(root);* *if (root-left == NULL) {* ** *do {* *node = pop();* *if

Re: [algogeeks] Re: Amazon Telephonic Interview Questions

2011-06-30 Thread Apoorve Mohan
1. int chk_bst(node *root) { if(root) { enqueue(root); while(!isempty()) { p=dequeue(); if(p-left) { if(!(p-left-data p-data)) return 0; enqueue(p-left); } if(p-right) { if(!(p-right-data = p-data)) return 0; enqueue(p-right);

Re: [algogeeks] Binary Tree

2011-06-30 Thread sagar pareek
Try traversing in LEVEL order and maintain array for each level...(Levels can be found by height of tree) then try by calculating sums starting from root(level zero) to higher level. Its typical to explain here but i found it as a solution and that will definitely found the solution. On Thu, Jun

Re: [algogeeks] Re: Yahoo Question

2011-06-30 Thread pacific :-)
Oh I got it. If ( interview at google) { Map reduce } else if(interview at yahoo) { Hadoop } else { Your personal preference. } On Thu, Jun 30, 2011 at 4:02 AM, bittu shashank7andr...@gmail.com wrote: 1.Use Haddop Map Reduce Framework .Obviously We Need Distributed Algo we will make

Re: [algogeeks] linked list

2011-06-30 Thread sagar pareek
Here is one approach which works :) Traverse the list from a pointer name ptr when encounter odd then start traversing from a tmp pointer (start point is ptr-next) to find even no. when find it swap the numbers. then again start forwarding ptr. If during traversing ptr==tmp make flag=0(at start

Re: [algogeeks] Re: Sort - Consecutive Array in O(n)

2011-06-30 Thread hary rathor
can we not use count sort because of O(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] linked list

2011-06-30 Thread Anantha Krishnan
Check this http://ideone.com/1I40z On Wed, Jun 29, 2011 at 8:04 PM, Nishant Mittal mittal.nishan...@gmail.comwrote: segregate even and odd nodes in a singly linked list.Order of even and odd numbers must be same... e.g:- i/p list is 4-1-3-6-12-8-7-NULL o/p list 4-6-12-8-1-3-7-NULL --

Re: [algogeeks] linked list

2011-06-30 Thread Anantha Krishnan
@sagar pareek If there are more fields in the node like: struct node{ int data; float mark; char ch; struct node *link; }; Here swapping *data* alone will corrupt the list right!! On Thu, Jun 30, 2011 at 4:38 PM, sagar pareek sagarpar...@gmail.com wrote: Here is one

[algogeeks] meaning of null in output

2011-06-30 Thread himanshu kansal
what is meaning of (null) in d output in cnd what r d possible reason nd causes for dt -- 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,

[algogeeks] conditional compilation

2011-06-30 Thread himanshu kansal
somewhere i read dt conditional compilation such as #if and #elif etc cn only use constant expressions and previously defined macrosthey cant use variables cz preprocessng is done b4 compilation... bt whn i try it on gcc and vc both r compiling it with variables abs. fyneven disabling

[algogeeks] Re: conditional compilation

2011-06-30 Thread himanshu kansal
1 more thngif its possible to eval. variable expression lyk abv... thn... int i=2; #if i==2 printf(hi); #else printf(bye); //prints byei think it shld print hi... #endif even this code prints bye. int i=3; #if i==2 printf(hi); #else printf(bye); #endif On Thu, Jun 30, 2011 at

Re: [algogeeks] Binary Tree

2011-06-30 Thread pacific :-)
My approach : int FindPath(Node n , sum s ) { FindPath(n-left , s ) || FindPath(n-right , s) || OneOf { a1 = AllSumsFromLeafToRoot( n-left ) } + n-value + Oneof { a2 = AllSumsFromLeafToRoot( n-right ) == s ) } // Use a1 and a2 to find out the actual path } Here all possible

[algogeeks] Partial Roundrobin Generation

2011-06-30 Thread richardmathur
Hello, I've been working on a problem in which I want to generate half, partial, and full round-robin schedules for teams. The half roundrobin was no problem, and the full can be done by repeating the process and by checking who was home/away in the first half roundrobin and flipping it in the

[algogeeks] Another spoj problem

2011-06-30 Thread saurabh singh
Any idea how to solve this problem? I am currently using graph and counting adjacent edges for the index. 1 2 \ \ 3 eg for this graph structure 2 will have maximum possible friends.I am still sorting out the bugs in my code. Anybody has better solution? -- Saurabh Singh B.Tech (Computer

[algogeeks] Constructing a Binary Search Tree from Post Order traversal-Possible or not

2011-06-30 Thread oppilas .
Is it possible to create a binary search tree (not binary tree) from post order traversal only? If give, how and if not please give reason/counter examples. -- 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: Constructing a Binary Search Tree from Post Order traversal-Possible or not

2011-06-30 Thread Nishant
if BST contains integers then sort the postorder traversal which will give you inorder traversal... On Jun 30, 6:27 pm, oppilas . jatka.oppimi...@gmail.com wrote: Is it possible to create a binary search tree (not binary tree) from post order traversal only? If give, how and if not please give

Re: [algogeeks] Re: Constructing a Binary Search Tree from Post Order traversal-Possible or not

2011-06-30 Thread sunny agrawal
it can be done without sorting(Finding any other traversal) Do it recursively, last element of the traversal will be head, and now if you will see in the traversal left part of the traversal will be its LST and Right will be RST (except Head) only thing you need to find will be the index of the

Re: [algogeeks] Another spoj problem

2011-06-30 Thread sunny agrawal
Problem Link ? On Thu, Jun 30, 2011 at 6:48 PM, saurabh singh saurab...@gmail.com wrote: Any idea how to solve this problem? I am currently using graph and counting adjacent edges for the index. 1 2 \ \ 3 eg for this graph structure 2 will have maximum possible friends.I am still

Re: [algogeeks] Another spoj problem

2011-06-30 Thread saurabh singh
very sorry.. https://www.spoj.pl/problems/socialne/ https://www.spoj.pl/problems/socialne/apologies once again On Thu, Jun 30, 2011 at 7:23 PM, sunny agrawal sunny816.i...@gmail.comwrote: Problem Link ? On Thu, Jun 30, 2011 at 6:48 PM, saurabh singh saurab...@gmail.comwrote: Any idea

Re: [algogeeks] Another spoj problem

2011-06-30 Thread saurabh singh
http://www.spoj.pl/problems/SOCIALNE/ On Thu, Jun 30, 2011 at 7:25 PM, saurabh singh saurab...@gmail.com wrote: very sorry.. https://www.spoj.pl/problems/socialne/ https://www.spoj.pl/problems/socialne/apologies once again On Thu, Jun 30, 2011 at 7:23 PM, sunny agrawal

Re: [algogeeks] Re: Constructing a Binary Search Tree from Post Order traversal-Possible or not

2011-06-30 Thread oppilas .
I am unable to find a test case where this particular approach fails( I hardly thinks it's correct but anyway here it is). We make the last element the root of the BST. And keep inserting each element one by one just like normal binary tree insertion. This will take O(n^2) time in worst case(

Re: [algogeeks] Re: Constructing a Binary Search Tree from Post Order traversal-Possible or not

2011-06-30 Thread Anantha Krishnan
Check this http://ideone.com/ARsJ1 On Thu, Jun 30, 2011 at 7:48 PM, oppilas . jatka.oppimi...@gmail.comwrote: I am unable to find a test case where this particular approach fails( I hardly thinks it's correct but anyway here it is). We make the last element the root of the BST. And keep

[algogeeks] Re: SPOJ GPA1

2011-06-30 Thread cegprakash
@kartik sachan: I just compared your output file with the output file for this test case 5 1 2 3 4 5 19 ab ab 100 50 20 20 20 75 75 10 0 ab 88 0 13 12 15.5 88 99 12 7 9 66 66 11 ab ab 99 100 your code outputs FAILED, 4.35 but actually he's PASSED, 7.20 I think you are assuming he's fail if he

Re: [algogeeks] Office Suite

2011-06-30 Thread Jitendra singh
circular linklist containing three pointers start,end,current On 6/27/11, vaibhav agarwal vibhu.bitspil...@gmail.com wrote: @radha k but i think we need to store the bottom of the stack for deleting the last node in O(1). as we can click the redo or undo fixed number of times and we would

[algogeeks] Java Developer Needed in MD -- F2F required

2011-06-30 Thread Leon Parker
Hello Associates, Wishes for the day!! Please go through the below requirement and let me know if you have any consultants for the below position? *Job Title: Java Developer Location: Silver Spring, MD Duration: 7-12 Months* Must have skills: Java 5; JEE technologies Expertise with Spring,

Re: [algogeeks] Java Developer Needed in MD -- F2F required

2011-06-30 Thread shady
banned On Thu, Jun 30, 2011 at 10:13 PM, Leon Parker leon.pan...@gmail.com wrote: Hello Associates, Wishes for the day!! Please go through the below requirement and let me know if you have any consultants for the below position? *Job Title: Java Developer Location: Silver Spring, MD

Re: [algogeeks] Java Developer Needed in MD -- F2F required

2011-06-30 Thread Naveen Kumar
banned in 6 mins pretty cool... :) On Thu, Jun 30, 2011 at 10:19 PM, shady sinv...@gmail.com wrote: banned On Thu, Jun 30, 2011 at 10:13 PM, Leon Parker leon.pan...@gmail.com wrote: Hello Associates, Wishes for the day!! Please go through the below requirement and let me know if you have

Re: [algogeeks] Office Suite

2011-06-30 Thread shady
stack is the best option, isnt it ? O(1) for both operations. On Thu, Jun 30, 2011 at 9:55 PM, Jitendra singh jsinghrath...@gmail.comwrote: circular linklist containing three pointers start,end,current On 6/27/11, vaibhav agarwal vibhu.bitspil...@gmail.com wrote: @radha k but i think we

Re: [algogeeks] Google Interview

2011-06-30 Thread Sriganesh Krishnan
can anybody give an example...pls.. On Thu, Jun 30, 2011 at 9:26 AM, Jitendra singh jsinghrath...@gmail.comwrote: kthlargest(a[],b[],lefta,righta,leftb,rightb,k) { mida=lefta+(righta-lefta)/2; midb=leftb+(rightb-leftb)/2; if(a[mida]bmidb])

[algogeeks] null macro

2011-06-30 Thread simran
null macro is defined as #define NULL (void*)0..is there any difference in null macro definition in c and c++? -- 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

[algogeeks] Re: Google Interview

2011-06-30 Thread Dumanshu
@Jitendra: where r u using k in the first call? On Jun 30, 8:56 am, Jitendra singh jsinghrath...@gmail.com wrote: kthlargest(a[],b[],lefta,righta,leftb,rightb,k) {   mida=lefta+(righta-lefta)/2;   midb=leftb+(rightb-leftb)/2;    if(a[mida]bmidb])      

Re: [algogeeks] Office Suite

2011-06-30 Thread Ashish Goel
stack, real implmentation is also stack AFAIK Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, Jun 30, 2011 at 10:34 PM, shady sinv...@gmail.com wrote: stack is the best option, isnt it ? O(1) for both operations. On Thu, Jun 30, 2011 at

Re: [algogeeks] Printing unique rows.

2011-06-30 Thread Jitendra singh
we can convert all rows in an equivalent integer and then sort all numbers and for(int i=1;i=n;i++) { if(sorted[i]==sorted[i-1]) prinf(sorted[i]); } On 6/28/11, sunny agrawal sunny816.i...@gmail.com wrote: @Ankit if N is large how will you hash the rows, numbers will be very large can

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-30 Thread Dumanshu
heres the code: http://ideone.com/aiG1m using the algo from http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ On Jun 21, 11:31 pm, Swathi chukka.swa...@gmail.com wrote: Does any one know how to return the Longest palindrome in a string in O(n). From

Re: [algogeeks] Re: POWER CRISES :Spoj

2011-06-30 Thread hpahuja.mnnit
any1??? On Thu, Jun 30, 2011 at 12:45 AM, harshit pahuja hpahuja.mn...@gmail.comwrote: @rizwaan u r ryt bt i want a O(n) soln .. whats say On Wed, Jun 29, 2011 at 2:55 PM, rizwan hudda rizwanhu...@gmail.comwrote: http://ideone.com/MSLXT The

[algogeeks] Re: MS

2011-06-30 Thread bittu
lets take the example {1,2, 10, 2, 3, 5, 1, 1,2,3,5,2} clearly min distance is 1 between a=2 b=5 take variables current=-1 min=INT_Max so we start from last element say its index is last which is array size -1 check it with a b if its equal to any of these then check current !=-

Re: [algogeeks] null macro

2011-06-30 Thread amit kumar
no difference On Thu, Jun 30, 2011 at 11:24 PM, simran ngxprerna2...@gmail.com wrote: null macro is defined as #define NULL (void*)0..is there any difference in null macro definition in c and c++? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] c output:

2011-06-30 Thread hary rathor
program 1; output :1 int main() { int i; i= 1,2,3; printf(i:%d\n,i); return 0; } program 2; output: ERROR int main() { int i=1,2,3; printf(i:%d\n,i); return 0; } pls explain -- You received this message because you

[algogeeks] please explain

2011-06-30 Thread ashwini singh
this code gives an error ([Warning] passing arg 1 of `maxdiff' makes integer from pointer without a cast) . Please explain the reasons. #includestdio.h #includeconio.h int maxdiff(int ); main() { int p,arr[]={2,4,1,6,23,4}; p=maxdiff(arr); printf(\n MAX Diff is \t %d,p);

Re: [algogeeks] c output:

2011-06-30 Thread aditya kumar
@harry: it ll b btr if u go to this link n clr ur doubts link : http://en.wikipedia.org/wiki/Comma_operator On Fri, Jul 1, 2011 at 3:56 AM, hary rathor harry.rat...@gmail.com wrote: program 1; output :1 int main() { int i; i= 1,2,3; printf(i:%d\n,i);

Re: [algogeeks] please explain

2011-06-30 Thread Rujin Cao
int maxdiff(int ); int maxdiff(int arr[]); The signatures of maxdiff function are not the same. On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh asingh...@gmail.com wrote: this code gives an error ([Warning] passing arg 1 of `maxdiff' makes integer from pointer without a cast) . Please

Re: [algogeeks] please explain

2011-06-30 Thread ashwini singh
still it's not working On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao drizzle...@gmail.com wrote: int maxdiff(int ); int maxdiff(int arr[]); The signatures of maxdiff function are not the same. On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh asingh...@gmail.com wrote: this code gives an

Re: [algogeeks] please explain

2011-06-30 Thread varun pahwa
actually u r passing arr,and receiving arr[] which actually receives the first element address. So arr will be a reference to first address. so its size will be 4 bytes and arr size will also be 4 bytes. so ur len contains only 1. so ur loop runs only once.i hope it clears. On Thu, Jun 30, 2011

[algogeeks] Re: Google Interview

2011-06-30 Thread Dumanshu
check this code http://ideone.com/rX130 compares k/2 values of each array taking care of extremes. On Jun 24, 9:48 pm, Decipher ankurseth...@gmail.com wrote: Can anybody please explain how to solve this question with logarithmic time complexity ? Write the code/algorithm to find the k-th

[algogeeks] Re: conditional compilation

2011-06-30 Thread Dumanshu
i think it will take a garbage value for i because these are preprocessor directives. On Jun 30, 4:46 pm, himanshu kansal himanshukansal...@gmail.com wrote: 1 more thngif its possible to eval. variable expression lyk abv... thn... int i=2; #if i==2 printf(hi); #else printf(bye);    

[algogeeks] Interview Questions ebook

2011-06-30 Thread Antony Kotre
please suggest me or mail me a good interview questions ebook thanks -- 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] please explain

2011-06-30 Thread Vishal Thanki
Rujin is right, here is the code which compiles.. vishal@ubuntu:~/progs/c\ 11:04:37 AM $ cat alg.c #includestdio.h int maxdiff(int arr[]); int main() { int p,arr[]={2,4,1,6,23,4}; p=maxdiff(arr); printf(\n MAX Diff is \t %d,p); return 0; } int maxdiff(int arr[]) {

Re: [algogeeks] please explain

2011-06-30 Thread shady
why is the value of sizeof(arr) in maxdiff function = 4 ? where as in main function it is 24 On Fri, Jul 1, 2011 at 11:05 AM, Vishal Thanki vishaltha...@gmail.comwrote: Rujin is right, here is the code which compiles.. vishal@ubuntu:~/progs/c\ 11:04:37 AM $ cat alg.c #includestdio.h int