Re: [algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-31 Thread atul anand
ok so by doing right=mid; and left=mid; in the if and else if block. you are narrowing down the range...?? thanks for the explanation :) -- 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] Re: DP problems in SPOJ

2011-12-31 Thread atul anand
here is solution for non-decreasing number using simple recursion. static int min=0; static int flag=0; int nonDec(int num) { if(num==0) { return 0; } nonDec(num/10); if(flag==1) { return -1; // not a non-decreasing number. } if(min = (num%10)) { min=num%10; } else { flag=1; return -1; }

Re: [algogeeks] Re: DP problems in SPOJ

2011-12-31 Thread atul anand
ok question was different we have to find total number.. On Sat, Dec 31, 2011 at 2:08 PM, atul anand atul.87fri...@gmail.com wrote: here is solution for non-decreasing number using simple recursion. static int min=0; static int flag=0; int nonDec(int num) { if(num==0) { return 0;

Re: [algogeeks] MICROSOFT IDC: unsorted linked lists intersection

2011-12-31 Thread Ashish Goel
merge two linked list without sorting them, the resultant list should be sorted one... any other better solution? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Wed, Jan 12, 2011 at 3:15 PM, Ashish Goel ashg...@gmail.com wrote: without

Re: [algogeeks] Re: DP problems in SPOJ

2011-12-31 Thread atul anand
correction in Lucifier code :- if (N 1) { int iter = 0; int totalCount = 10; // this is when N = 1 ... for (int i=0; i = 9; ++i) // earlier for (int i=0; i ** 9; ++i) A[i] = 1; while(++iter N) { for (int i = 8; i 0 ; --i) { A[i]+= A[i+1];// earlier

[algogeeks] Re: DP problems in SPOJ

2011-12-31 Thread Lucifer
@atul There is no. correction.. The for loop is correct.. It should be: for (int i =0; i 9; ++i) On 31 Dec, 16:02, atul anand atul.87fri...@gmail.com wrote: correction in Lucifier code :- if (N 1) {   int iter = 0;   int totalCount = 10; // this is when N = 1 ...   for (int i=0; i = 9;

[algogeeks] Re: DP problems in SPOJ

2011-12-31 Thread Lucifer
@atul.. Yes, A[i] += A[i+1] is correct.. Another correction that is required is : for (int i = 7; i = 0 ; --i) // earlier for (int i = *8*; i 0 ; -- i) On 31 Dec, 16:10, Lucifer sourabhd2...@gmail.com wrote: @atul There is no. correction.. The for loop is correct.. It should be: for

[algogeeks] Re: DP problems in SPOJ

2011-12-31 Thread Lucifer
@atul.. It seems that in the example explained above i have done it correctly but while jolting down the code i messed up the indexing.. Thanks for bringing it up .. :) On 31 Dec, 16:17, Lucifer sourabhd2...@gmail.com wrote: @atul.. Yes, A[i] += A[i+1] is correct.. Another correction that

[algogeeks] Re: MICROSOFT IDC: unsorted linked lists intersection

2011-12-31 Thread Lucifer
@Ashish.. I have something in mind.. but would require verification by u.. Lets say, the structure of the data node is as follows: struct node { int data; struct node *next; }; Now, given 2 sorted linked lists we can right a O(N) time and in-place merge process, to build a sorted merged

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-31 Thread Lucifer
@atul.. Yup.. exactly.. i think the problem is itself about narrowing the range and works really well as each node can have only one child.. :) On 31 Dec, 13:09, atul anand atul.87fri...@gmail.com wrote: ok so by doing right=mid; and left=mid; in the if and else if block. you are narrowing

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-31 Thread top coder
Nice Solution and explanation Lucifer :) On Dec 31, 4:48 pm, Lucifer sourabhd2...@gmail.com wrote: @atul.. Yup.. exactly.. i think the problem is itself about narrowing the range and works really well as each node can have only one child.. :) On 31 Dec, 13:09, atul anand

[algogeeks] Divide the Square into 2 parts

2011-12-31 Thread top coder
Within a 2D space, there is a batch of points(no duplicate) in the region (0,0),(0,1),(1,0),(1,1), try to find a line which can divide the region to 2 parts with half points in each .the input will be an array of points and the length of the array. struct point{ int x; int y; }; input :

Re: [algogeeks] amazon ques

2011-12-31 Thread Ashish Goel
the LL has to be a DLL as deletion would be a prob otherwise. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, Oct 1, 2011 at 9:42 AM, SAMM somnath.nit...@gmail.com wrote: Linked List + Hash table will serve the purpose in O(1). On 9/30/11,

Re: [algogeeks] Re: DP problems in SPOJ

2011-12-31 Thread atul anand
@Lucifier : i wrote for (int i=0; i = 9; ++i) because i was considering index from 1 to n not 0 to n-1; you are considering from 0 to n-1. so both are correct. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] Re: Longest sequence of numbers with atmost diff K

2011-12-31 Thread Lucifer
O(N^2) approach.. --- Say the current start index is i.. Then starting from i keep track of the min and max element and ensure that the diff of max and min is =K. Say the diff exceeds at index j, then the current continuous subarray size would be (j - i) and we

Re: [algogeeks] Determine if BST has single child for every node given pre order

2011-12-31 Thread Apoorve Mohan
Hey Below is a solution. Hope it works. Let 'n' be the size of the array we have. max = min = array(n-1) flag=1; for(i=(n-2) to 0) { if(array(i)array(i+1)) { if(min array(i)) { flag = 0; break; } else { min = array(i); } } else

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-31 Thread Lucifer
@apoorve say the input is 9 8.. I think it will fail... Secondly, i see that max is not being used On Dec 31, 8:19 pm, Apoorve Mohan apoorvemo...@gmail.com wrote: Hey Below is a solution. Hope it works. Let 'n' be the size of the array we have. max = min = array(n-1) flag=1;

Re: [algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-31 Thread Apoorve Mohan
Hey It was a typo error. here it goes.. max = min = array(n-1) flag=1; for(i=(n-2) to 0) { if(array(i)array(i+1)) { if(min array(i)) { flag = 0; break; } else { min = array(i); } } else { if(max array(i)) {

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-31 Thread Lucifer
@Apoorva.. I think i misread your code at the beginning ( apart from the typo) If i m not wrong then you have a taken a bottom up approach to solve the problem using the range concept.. Wherein the code that i posted is a top down approach.. Great .. :) On 31 Dec, 21:30, Apoorve Mohan

[algogeeks] Re: Longest sequence of numbers with atmost diff K

2011-12-31 Thread Lucifer
@above Correction.. i can be = R... hence, which can be found as part of traversal.. Another addition: I have explained the concept using A[j] to be max.. In case A[j] is min, then we will take a similar approach keeping in mind that R will be closest but in terms of finding the max element..

Re: [algogeeks] Re: Longest sequence of numbers with atmost diff K

2011-12-31 Thread ankit gupta
HNY 2012(IST) in between to all members and happy coding for 2012 may all your compilation produce ZERO errors On Sun, Jan 1, 2012 at 12:01 AM, Lucifer sourabhd2...@gmail.com wrote: @above Correction.. i can be = R... hence, which can be found as part of traversal.. Another addition: I

Re: [algogeeks] Re: Longest sequence of numbers with atmost diff K

2011-12-31 Thread atul anand
*if (max - min k) //* this code is unreachable in the while loop. break; -- 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] Re: Longest sequence of numbers with atmost diff K

2011-12-31 Thread atul anand
remove continue in while loop...then it will work fine. On Sun, Jan 1, 2012 at 12:49 AM, atul anand atul.87fri...@gmail.com wrote: *if (max - min k) //* this code is unreachable in the while loop. break; -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: Longest sequence of numbers with atmost diff K

2011-12-31 Thread atul anand
start=0; maxLen=0; min=arr[0]; max=arr[0]; j=0; for(i=1;in;i++) { if(arr[i] max) max=arr[i]; else if(arr[i] min) min=arr[i]; if( (max - min ) k maxLen ( i - j ) ) { maxLen=i - j; start=j;

[algogeeks] Re: Longest sequence of numbers with atmost diff K

2011-12-31 Thread Lucifer
@atul.. No need to remove continue.. 'continue' has been added for optimization.. (max - min) K, should only be checked when either we get a new min or max... In case the current processed element is neither a good fit for max or min then we need not check for the difference.. On Jan 1, 2:33 

Re: [algogeeks] Re: Divide the Square into 2 parts

2011-12-31 Thread Ravi Ranjan
@ dave what about the problem if it dsnt satisfy the 2 conditions(odd/even) -- 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