[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 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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 4 5 40 41  19 20
4   1   2   3   4   5   40  41
19  20
Max : [139]
which is wrong

Here is the code of Kadane's Algorithm, u can check it on your own :
#includestdio.h

int main(){
int n;
int max,a,b;
int curr,aa,bb;
int arr[1000];
int i;

printf(Enter numbers (-1 to stop taking input) :);
for(i=0 ; i1000 ; i++){
scanf(%d,arr[i]);
if(arr[i] == -1){
n=i;
break;
}
}

max = -9;
a = b = 0;

curr = 0;
aa = 0;

for(bb=0 ; bbn ; bb++){
curr = curr + arr[bb];

if(curr  max){
max = curr;
a = aa;
b = bb;
}

if(curr  0){
curr = 0;
aa = bb + 1;
}
}

for(i=a ; i=b ; i++){
printf(%d\t,arr[i]);
}
printf(\nMax : [%d]\n,max);

return 0;
}



===

On Sep 18, 10:29 pm, Minotauraus anike...@gmail.com wrote:
 I was looking into this problem the other day and found 
 this:http://www.algorithmist.com/index.php/Kadane's_Algorithm
 Kadane's algorithm to find the maximum continuous subarray.

 The basic idea is to maintain the largest sum ending at each location
 in the array. and max which holds the maximum so far.

 On Sep 17, 11:41 am, Raj Jagvanshi raj.jagvan...@gmail.com wrote:



  a[] = {4,1,2,3,4,5,40,41,19,20};

  print = 40 , 41
  sum  = 81;

  give me code

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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
---



Here is my code:
#includestdio.h

int main(){
int arr[100],i,N;

int max,smax,emax;
int curr,scurr;

printf(Enter numbers (-1 to stop taking input)\n\n);
for(i=0 ; i100 ; i++){
scanf(%d,arr[i]);
// Enter -1 to stop entering the numbers
if(arr[i] == -1){
N=i;
break;
}
}

//
max = arr[0];
curr = arr[0];
smax = emax = scurr = 0;

for(i=1 ; iN ; i++){
if( (arr[i-1]+1 == arr[i])  (curr  curr + arr[i]) )
{
curr = curr + arr[i];
}else{
scurr=i;
curr = arr[i];
}

if(max  curr){
smax = scurr;
emax = i;

max = curr;
}
}
// end

printf(\n\nLargest sequence is : %d to %d
\n,arr[smax],arr[emax]);
for(i=smax ; i=emax ; i++){
printf(%d\t,arr[i]);
}
printf(\nSum: %d\n,max);

return 0;
}

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 wrong.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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++)
{
for(loop2=0;loop2num;loop2++)  // SORTING
{
if(a[loop1]a[loop2])
{
temp=a[loop1];
a[loop1]=a[loop2];
a[loop2]=temp;
}
}
}

for(loop1=0;loop1num;loop1++)  // CONDITION CHECKING
{
if(a[loop1]==a[loop1+1]+1)
{
printf(TWO NUMBERS ARE %d, %d and their sum is
%d,a[loop1],a[loop1+1],a[loop1]+a[loop1+1]);
loop2=0;
break;
}
}
if(loop2!=0)
{
printf(NO SUCH ENTRIES FOUND);
}
getch();
}




On Sun, Sep 19, 2010 at 11:57 AM, Krunal Modi krunalam...@gmail.com wrote:

 @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 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 and thts it.

On Sat, Sep 18, 2010 at 11:12 PM, jagadish jagadish1...@gmail.com wrote:

 You are given a string which is sorted.. Write a recursive function to
 remove the duplicate characters in the string.
 eg: potatoeos
 output: potaes
 NO extraspace like hash/ bitmaps..

 --
 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 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 and thts it.

 On Sat, Sep 18, 2010 at 11:12 PM, jagadish jagadish1...@gmail.com wrote:

 You are given a string which is sorted.. Write a recursive function to
 remove the duplicate characters in the string.
 eg: potatoeos
 output: potaes
 NO extraspace like hash/ bitmaps..

 --
 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Umer

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 be using division..


additionally, you can improve it if any of the numbers is zero






Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Sun, Sep 19, 2010 at 8:18 PM, bittu shashank7andr...@gmail.com wrote:


 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 wrong...

On 9/19/10, Krunal Modi krunalam...@gmail.com wrote:
 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 email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 handling
before[i] = before[i-1];
after[length-1-i] = after[length-i];
  }
  else if (numberofZeros=1)
  {
before[i]=a[i]*before[i-1];
after[length-1-i]=a[length-1-i]*after[length-i];
  }
  else break; //Case2 handling
}

for(int i=0;ilength; i++) // replace array contents as per the question.
{
if(numberofZeros == 1)
{
  if(i ==index)
   a[index] = before[index] * after[index];
   else
   a[i] = 0;
}
else if(numberofZeros1)
{
 a[i]=0;
}
else
{
  a[i] = before[i] * after[i];
}
}

Thanks,
NagRaaj.

On Sun, Sep 19, 2010 at 8:24 PM, 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];
  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 be using division..


 additionally, you can improve it if any of the numbers is zero






 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652


 On Sun, Sep 19, 2010 at 8:18 PM, bittu shashank7andr...@gmail.com wrote:


 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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];
  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 be using division..


 additionally, you can improve it if any of the numbers is zero






 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652


 On Sun, Sep 19, 2010 at 8:18 PM, bittu shashank7andr...@gmail.com wrote:


 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



 --
 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+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 to remove them and move the remaining elements forward.


On Sep 19, 3:50 am, Umer Farooq the.um...@gmail.com wrote:
 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 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 and thts it.

  On Sat, Sep 18, 2010 at 11:12 PM, jagadish jagadish1...@gmail.com wrote:

  You are given a string which is sorted.. Write a recursive function to
  remove the duplicate characters in the string.
  eg: potatoeos
  output: potaes
  NO extraspace like hash/ bitmaps..

  --
  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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups
   .com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

   --
  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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups 
  .com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 Umer

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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, Navin Naidu navinmna...@gmail.com wrote:
 Use Max-Heap, add first ten elements, the root element will be max,

 Next Iteration, remove a[0] and add a[10], max-heapify.









 On Fri, Sep 17, 2010 at 1:48 PM, Tech Id tech.login@gmail.com wrote:
  You have an array of 100 integers.
  There is a window of 10 elements which starts from 0th element and
  moves by 1 element till the 90th element.
  We need to print the maximum element for all the positions of the
  window.

  Hint:
  For the first position of the window, you have to find the maximum as
  done normally for any array.
  After that, when the window moves by 1 element, you just have to
  consider one more element and forget the very first element to find
  the new maximum. Thus, after the first max, it should take much less
  time to find the max for all the other window positions.

  --
  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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups 
  .com
  .
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 Thanks  Regards,

 - NMN

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 elements are in order.
example:

8 7 4 2 3 9

Here, 3  2, so reverse (4),

3 2 4 7 8 9
reverse (1)
 2 3 4 7 89

now continue, but look for smaller elements than the previous.

in above example, if number was 5 (instead of 3, two more reverse
calls would be required).



On Sep 18, 9:13 pm, Krunal Modi krunalam...@gmail.com wrote:
 @Minotauras:

 There are some problems in you swap(x,y)
 in your example : for reverse(3) you have considered 0 based indexing
 and for reverse(2) 1 based index !!
 see:
 Original array : 1 8 3 4 5 and we want to swap(2,3) // swap 3 and 4.
 Means, 0 BASED INDEX

 reverse(3): 4 3 8 1 5
 reverse(2): 8 3 4 1 5 
 reverse(3): 1 4 3 8 5

 AND

 If you meant swap(x,y)  = rev(y) ; rev(1) ; rev(y) then, your
 swap(x,y) can't be used in ALL sorting algos.

 For example,
 Original array : 1 4 3 2
 and we want to swap(1,3) // because we want 1 2 3 4
 so
 rev(3) - 2 3 4 1
 rev(1) - 3 2 4 1
 rev(3) - 1 4 2 3

 So we have a restriction of swapping only two consecutive numbers
 so...In swap(x,y) x is not needed because {xy  x+1=y}

 On Sep 17, 12:17 am, Minotauraus anike...@gmail.com wrote:







  write a function swap(x, y)
  which does:
  reverse(y)
  reverse(1)
  reverse(y)

  so 1 8 3 4 5, swap (2, 3) // swap 3 and 4
  reverse(3) gives: 4 3 8 1 5
  reverse(2) : 3 4 8 1 5
  reverse(3): 1 8 3 4 5 //thus we have swapped 3, 4 using the reverse(x)
  function.

  Use any sorting algorithm and you'll need 3k * n(log n)
  assuming reverse(x) takes O(k)

  I guess there is a way to optimize the number of reverse(x) calls

  On Sep 16, 8:41 am, Srinivas lavudyasrinivas0...@gmail.com wrote:

   You have been given a function rev(x) which works as follows:
   It reverses a[0] to a[x] elements of a.
   e.g. Given array is
   a : 1 8 3 4 5
   rev(3) will convert the array to
   a : 4 3 8 1 5
   Use this function only (and comparison, of course) to sort given array
   'a'. The only criterion is
   that the number of times this function is called should be minimum.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 I knew this^ back
then.


On Sep 19, 7:48 am, bittu shashank7andr...@gmail.com wrote:
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 9:27 PM, Minotauraus anike...@gmail.com wrote:

 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 I knew this^ back
 then.


 On Sep 19, 7:48 am, bittu shashank7andr...@gmail.com wrote:
  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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 of moves in which the process is repeated depends on the index
of the maximum element.(may not be 10 moves everytime)
Correct me if i am wrong.

On Sun, Sep 19, 2010 at 9:38 PM, Minotauraus anike...@gmail.com wrote:

 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, Navin Naidu navinmna...@gmail.com wrote:
  Use Max-Heap, add first ten elements, the root element will be max,
 
  Next Iteration, remove a[0] and add a[10], max-heapify.
 
 
 
 
 
 
 
 
 
  On Fri, Sep 17, 2010 at 1:48 PM, Tech Id tech.login@gmail.com
 wrote:
   You have an array of 100 integers.
   There is a window of 10 elements which starts from 0th element and
   moves by 1 element till the 90th element.
   We need to print the maximum element for all the positions of the
   window.
 
   Hint:
   For the first position of the window, you have to find the maximum as
   done normally for any array.
   After that, when the window moves by 1 element, you just have to
   consider one more element and forget the very first element to find
   the new maximum. Thus, after the first max, it should take much less
   time to find the max for all the other window positions.
 
   --
   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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups .com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
  --
  Thanks  Regards,
 
  - NMN

 --
 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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, 13, 14, 15, 16
___
A[]= {3, 1, 5, 9, 3, 2, 5, 4, 3, 4, 5, ..5, ..11, .4, .0, ..11,
99}
B[]= {5, 3, 4,11, 4}
___
The position of smallest window is [ 6, 8, 9, 12, 13 ].

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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. 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 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards,
Rahul Patil

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 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. 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 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Regards,
 Rahul Patil

  --
 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+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.