[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@LG JAYARAM : Your code is not even compiling. If you are including header that means you have made a code and successfully run it. I have the code readybut just wanted to check with your program for some exception conditions... -- You received this message because you are subscribed to the

[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@Minotauraus: This is not the thing that Raj Jagvanshi wants. See, what he has mentioned. a[] = {4,1,2,3,4,5,40,41,19,20}; print = 40 , 41 sum = 81; We need to find max sum such that they are of consecutive numbers (a,a +1,a+2,) I have implemented Kadane's Algo : and the result is 4 1 2 3

[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@Raj Jagvanshi: Test 1 : Enter numbers (-1 to stop taking input) 4 1 2 3 4 5 40 41 19 20 -1 Largest sequence is : 40 to 41 40 41 Sum: 81 -- Test 2: Enter numbers (-1 to stop taking input) -5 -4 -3 -1 Largest sequence is : -3 to -3 -3 Sum: -3

[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread soundar
1)get the numbers 2)Sort the numbers 3)traverse from first number 4)if (a[i]==a[i+1]-1 ) { count++; sum+=(a[i]+a[i+1]) i++; } 5)if (summax) { end=count; max=sum; } 6)print down to count no of elements from a[end] will this algorithm wok?correct me if i am

Re: [algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread LG JAYARAM .
Hey sorry buddy...here is the code #includestdio.h #includeconio.h void main() { int a[20],loop1,loop2,temp,num; // INITIALIZATION printf(ENTER THE ARRAY SIZE); scanf(%d,num); printf(ENTER THE NUMBERS); for(loop1=0;loop1num;loop1++) { scanf(%d,a[loop1]); } for(loop1=0;loop1num;loop1++) {

Re: [algogeeks] recursion to remove duplicate characters in a string

2010-09-19 Thread LG JAYARAM .
hi buddy ...Im clear with the ideahereby I share the concept... wat exactly need to be done to solve this task isbetter create a Binary search tree...the Binary search tree will not allow duplicates and If u perform a inorder traversalu can get the result...the task is oversimple

[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
@LG Jayaram : check for -5 -4 -3 -2 -1 answer should be : -1 -- 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 unsubscribe from this group, send email to

Re: [algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread LG JAYARAM .
How could it be -1,in the given array -1 and -2 are the largest numbersso their sum will be -3 rite On Sun, Sep 19, 2010 at 4:15 PM, Krunal Modi krunalam...@gmail.com wrote: @LG Jayaram : check for -5 -4 -3 -2 -1 answer should be : -1 -- You received this message because you are

[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Krunal Modi
no we have to find consecutive numbers such that there some is largest... here -3 -1 -- 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 unsubscribe from this group, send

Re: [algogeeks] recursion to remove duplicate characters in a string

2010-09-19 Thread Umer Farooq
creating a bst would require extra space. You can do this with an array of char dude. On Sun, Sep 19, 2010 at 3:31 PM, LG JAYARAM . lgj...@gmail.com wrote: hi buddy ...Im clear with the ideahereby I share the concept... wat exactly need to be done to solve this task isbetter create a

[algogeeks] Array Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-19 Thread bittu
Given an array of numbers, replace each number with the product of all the numbers in the array except the number itself *without* using division. -- 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] Array Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-19 Thread Ashish Goel
this is google question take arrays before[] and after before[0]=1 after[length-1]=1; for (int i=1; ilength;i++) { before[i]=a[i]*before[i-1]; after[length-1-i]=a[length-1-i]*after[length-i]; } now resuly for the asked index is after[index]*before[index] the idea here is that we should not

Re: [algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Soundar
but the 2 consecutive numbers condition violatesfor -1 we must take only -1 only then we get -1 .If u add 2 negative numbers the answer is less than the 2 elements..So if the array contains ONLY negative numbers the maximum sum can't be achieved for 2 elements.Correct me if i am

Re: [algogeeks] Array Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-19 Thread naga raju
Handling ' 0 's Case1: array containing single zero. Caae 2: array containing multiple zeros. int numberofZeros =0, index =0 ; before[0]=1 after[length-1]=1; for (int i=1; ilength;i++) { if( !a[i] ) //encountered zero { numberofZeros++; if(numberofZeros == 1) index =i; //Case1

Re: [algogeeks] Array Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-19 Thread Soundar
array index starting from 0 or 1? in the for loop i =length isn't it? If no please explain On 9/19/10, Ashish Goel ashg...@gmail.com wrote: this is google question take arrays before[] and after before[0]=1 after[length-1]=1; for (int i=1; ilength;i++) { before[i]=a[i]*before[i-1];

[algogeeks] Amazon Question-Linux Shell

2010-09-19 Thread bittu
Linux shell command to find all files in a directory which contain ip addresses -- 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 unsubscribe from this group, send email to

[algogeeks] Re: print largest continue subsequent in int array

2010-09-19 Thread Dave
Krunal: If the array contains only negative numbers, shouldn't the subsequence with the largest sum be the empty subsequence? Dave On Sep 19, 5:45 am, Krunal Modi krunalam...@gmail.com wrote: @LG Jayaram : check for -5 -4 -3 -2 -1 answer should be : -1 -- You received this message because

[algogeeks] Re: recursion to remove duplicate characters in a string

2010-09-19 Thread Minotauraus
Ummm and also, the potatoes example isn't a _**sorted string**_ as the problem statement said. All you have to do is pass the location of the current char and then compare it with the next one until you reach the end. Use a dynamic array or a list or something to store the chars in so it's easier

[algogeeks] Re: Finding max for all positions of a moving window

2010-09-19 Thread Minotauraus
You don't need any data structure. Since the window moves by one element each, you can simply count 10 such moves and compare each new element with currMax. If it's greater, overwrite currMax. After 10 moves you have your max for that 10 element window, rinse and repeat. On Sep 17, 1:31 am,

[algogeeks] Re: do this: sorting using reverse()

2010-09-19 Thread Minotauraus
Yeah, you're right. It'll work only for consecutive elements. And by swapping only consecutive elements, it'll take many swaps to sort the array. Another way would be to start from the left and every time you hit an element larger than the previous one, call reverse successively until all

[algogeeks] Re: Array Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-19 Thread Minotauraus
It's been discussed here before. Start by multiplying from either sides of the array and stop when both pointers reach the opposite side. takes O(n) time and does not involve division so won't crap out for cases where some of the elements are 0. I was asked this for my Google phone screen I wish

Re: [algogeeks] Re: Array Good One!!!!!!!!!!!!!!!!!!!!!!

2010-09-19 Thread kartheek muthyala
I guess before[index] should contain product of the numbers before index and after[index] should contain all the product after the index but @Ashish algo isn't that before[index] contains product that includes the number at the index position also. Please clarify me... On Sun, Sep 19, 2010 at

Re: [algogeeks] Re: Finding max for all positions of a moving window

2010-09-19 Thread kartheek muthyala
@Minotauraus, if we consider your scenario, 10 12 14 9 23 2 4 6 9 19 22 10 6 12 10 for 1st window max=23 second window max=23(2322) third windw max=23(2310) fourth window max=23(236) fifth window max=23(2312) sixth window max =22(calculate the maximum in the window). repeat again So the number

[algogeeks] do this:Finding Smallest window

2010-09-19 Thread Srinivas
You are given two arrays A [n] and B[m] find the smallest window in A such that it contains all elements of B. i.e. find a position [g,h] such that A[g.k] contains all elements of B[m] For example, ___ index = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12,

[algogeeks] do this: two numbers with min diff

2010-09-19 Thread Srinivas
2 nos with min diff given an array of size n. find 2 numbers from array whose difference is least in O(n) w/o using xtra space( i mean constant space) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Multiplication of two numbers

2010-09-19 Thread Srinivas
how to find the no. of digits in the product of two numbers without multiplying?? if a is the number of digits in A and if b is the number of digits in B the number of digits in A*B is either a+b or a+b-1 but how to find the exact one? -- You received this message because you are subscribed to

Re: [algogeeks] Multiplication of two numbers

2010-09-19 Thread rahul patil
A partial solution is , if you multiply first digits of two nos and result is greater than 10 then surely result will be a+b digits If not, according to me, u will need a complex logic to solve. On Mon, Sep 20, 2010 at 10:41 AM, Srinivas lavudyasrinivas0...@gmail.comwrote: how to find the no.

Re: [algogeeks] Multiplication of two numbers

2010-09-19 Thread sumant hegde
Adding to the partial solution, if x, y are first digits, and x*y + x + y 10, the result will be a+b -1 digits. If not, u will need a complex logic to solve On Mon, Sep 20, 2010 at 10:50 AM, rahul patil rahul.deshmukhpa...@gmail.com wrote: A partial solution is , if you multiply first digits