[algogeeks] [Off-topic]If you have any issues about membership, read about google groups dont mail moderators and owners

2012-01-04 Thread shady


-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



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

2012-01-04 Thread Lucifer
@atul...

As usual an editing mistake :)
int X[2][N] -> int X[2][N+1];
-
Regarding the new fixed code's explanation:
Basically as explained by praveen..

There are 2 things that need to be done to solve the problem:
1) Pick 2 nos and see if their abs diff is > K or not.. If yes,
consider it to be 0 otherwise 1.
2) find the max sub square filed with 1's...

Now max subsquare can be found by using the following recurrence..
Say the 2D array which actually stores the 0-1 mapping is R[i.j],

F[i,j] -> the maximum subsquare that ends at 'i' row and 'j' column...

Hence,
F[i, j] = (R[i,j] == 0 ? 0 : 1 + min( F[i-1, j], F[i-1, j-1], F[i,
j-1] ) );

Now u can see that to calculate the value of F[i,j] we need access to
the prev row 'i-1' as well...

Hence, to reduce from 2-D array to 1-D array we need to do the
following:
1) Have a 1-D prev array for row 'i-1'
2) Have a 2-D curr array for row 'i'.
3) Calculate F[i,j] , on the fly and store its value in curr[j] ...
4) Once, all F[i,j]'s are calculated for the 'i'th row, make curr as
prev array and make prev as the curr array for next round of
calculations...
The reason being that, for 'i+1' iteration,
 prev should point to 'i' row which hold F[i], and
 curr should point to 'i+1' row to hold the new F[i+1] values..For
this we can use the array prev from the previous iteration..

Basically in X[2][N+1],
X[0] is prev , and
X[1] is curr..

Once we finish the current iteration and start a new one we switch the
roles of X[0] and X[1], rather than copying the values from X[1] to
X[0]...

--

Let me know if u have concerns...
--

On Jan 5, 12:44 am, gaurav bansal  wrote:
> @all
> sorry for my prev post.
>
> On Jan 5, 12:42 am, gaurav bansal  wrote:
>
>
>
>
>
>
>
> > your algo wont work for  a[]={8,11,2} with k=7.
> > acc to u,ans should be 3,but it is 2.
> > you are not considering the diff between max and min value

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



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

2012-01-04 Thread Lucifer
@atul..

First of all 6 is not in the heap but its index '0' is..

I think before also u had raised this question of heap stability and i
did explain with an example in one of my previous posts that it won't
affect the checks...
I m repeating the same explanation here with the reason why it won't
affect...

Say, for the given sequence where u think it will cause a problem
Now lets say that u are inside the while loop and the current top is
'0' i.e. value A[0] = 6,
Now, if currentstrt index is >0 say for ex- '4', then acc. to the
following check the value A[0] = 6, won't be considered for currentStr
and will be removed from the heap...After the removal the process of
finding the next max/min will repeat inside the while loop:

if (Top(MaxH) < currStartInd) '0' < '4' , hence remove and continue to
loop..
Remove(MaxH);

I have mentioned in one of my previous posts that the above check
guarantees the heap stability...

-

Please look for the post which starts with the below text , to refer
to the code:
/**
@topcoder..
Below i have added a semi pseudocode for better understanding..
Let me know if u want further explanation..
**/

Also, please to the post which starts with the below text, where i
have clarified ur doubts:
/**
@atul..
There are no stability or access issues with the code..
Below i have given explanation for ur concerns...
*/


If u find an example where the explanation fails, let me know...
-


On Jan 5, 12:44 am, gaurav bansal  wrote:
> @all
> sorry for my prev post.
>
> On Jan 5, 12:42 am, gaurav bansal  wrote:
>
>
>
>
>
>
>
> > your algo wont work for  a[]={8,11,2} with k=7.
> > acc to u,ans should be 3,but it is 2.
> > you are not considering the diff between max and min value

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



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

2012-01-04 Thread gaurav bansal
@all
sorry for my prev post.

On Jan 5, 12:42 am, gaurav bansal  wrote:
> your algo wont work for  a[]={8,11,2} with k=7.
> acc to u,ans should be 3,but it is 2.
> you are not considering the diff between max and min value

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



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

2012-01-04 Thread gaurav bansal
your algo wont work for  a[]={8,11,2} with k=7.
acc to u,ans should be 3,but it is 2.
you are not considering the diff between max and min value

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: check Similar array

2012-01-04 Thread atul anand
@Ankur : i guess this would work but to your test add one more sizeof(arr);

On Wed, Jan 4, 2012 at 10:00 PM, Ankur Garg  wrote:

> sorry it shud be
> sum of squares and xor and sumof elements
>
> I think this shud work
>
> Regards
> Ankur
>
>
>
>
> On Wed, Jan 4, 2012 at 9:52 PM, atul anand wrote:
>
>> @ Karthikeyan :
>>
>> sum of cubes fails:-
>>
>> arr1={2,3,0,-3} =   4
>> arr2={1,1,1,1}  = 4
>>
>> On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wrote:
>>
>>> Hi,
>>>
>>> Consider, arr1={1,2,3}  and arr2={-1,-2,-3}
>>>
>>> using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since
>>> square of 1 and -1 is 1)
>>>
>>> so it won work with this case
>>>
>>> 1.better take the square and negate it before adding
>>> or
>>> 2.take sum of cubes
>>>
>>> pls correct me if i'm wrong
>>>
>>> Regards,
>>> Karthikeyan
>>> PSG TECH
>>>
>>> --
>>> 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 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 algogeeks@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 algogeeks@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 algogeeks@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: check Similar array

2012-01-04 Thread Ankur Garg
sorry it shud be
sum of squares and xor and sumof elements

I think this shud work

Regards
Ankur



On Wed, Jan 4, 2012 at 9:52 PM, atul anand  wrote:

> @ Karthikeyan :
>
> sum of cubes fails:-
>
> arr1={2,3,0,-3} =   4
> arr2={1,1,1,1}  = 4
>
> On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wrote:
>
>> Hi,
>>
>> Consider, arr1={1,2,3}  and arr2={-1,-2,-3}
>>
>> using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since
>> square of 1 and -1 is 1)
>>
>> so it won work with this case
>>
>> 1.better take the square and negate it before adding
>> or
>> 2.take sum of cubes
>>
>> pls correct me if i'm wrong
>>
>> Regards,
>> Karthikeyan
>> PSG TECH
>>
>> --
>> 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 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 algogeeks@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 algogeeks@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: check Similar array

2012-01-04 Thread atul anand
@ Karthikeyan :

sum of cubes fails:-

arr1={2,3,0,-3} =   4
arr2={1,1,1,1}  = 4

On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B  wrote:

> Hi,
>
> Consider, arr1={1,2,3}  and arr2={-1,-2,-3}
>
> using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since
> square of 1 and -1 is 1)
>
> so it won work with this case
>
> 1.better take the square and negate it before adding
> or
> 2.take sum of cubes
>
> pls correct me if i'm wrong
>
> Regards,
> Karthikeyan
> PSG TECH
>
> --
> 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 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 algogeeks@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: check Similar array

2012-01-04 Thread atul anand
@ankur :

arr1={0,2,0,2);
arr2={1,1,1,1};

xor ans sum condition satisfy.

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: check Similar array

2012-01-04 Thread Ankur Garg
What if we check these 2 conditions

XOR and sum of elements  and sizeof array same

I cudnt find any counter example

Regards
Ankur

On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B  wrote:

> Hi,
>
> Consider, arr1={1,2,3}  and arr2={-1,-2,-3}
>
> using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since
> square of 1 and -1 is 1)
>
> so it won work with this case
>
> 1.better take the square and negate it before adding
> or
> 2.take sum of cubes
>
> pls correct me if i'm wrong
>
> Regards,
> Karthikeyan
> PSG TECH
>
> --
> 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 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 algogeeks@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: check Similar array

2012-01-04 Thread Karthikeyan V.B
Hi,

Consider, arr1={1,2,3}  and arr2={-1,-2,-3}

using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since square
of 1 and -1 is 1)

so it won work with this case

1.better take the square and negate it before adding
or
2.take sum of cubes

pls correct me if i'm wrong

Regards,
Karthikeyan
PSG TECH

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Amazon Onsite

2012-01-04 Thread gaurav arora
Sorry there is some correction

p[] : array of petrol
d[]:  array of distance

int FirstPetrolPump(int p[],int d[],int n)
{
int c=0,ThisPetrol=0,FirstPump=0,i;
 for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Playing with memory

2012-01-04 Thread Vanathi Algogeeks
*Playing with memory*

* *

Sindhu and Alistair play a memory game involving of a sequence of random

numbers between *1 *and *10*, inclusive, that is called out one at a time.



Each player can remember up to *5 *previous numbers. When the called

number is in a player's memory, that player is awarded a point. If it's not,

the player adds the called number to his memory, removing another number

if his memory is full.



Both players start with empty memories. Both players always add new

missed numbers to their memory but use a different strategy in deciding

which number to remove:



Sindhu's strategy is to remove the number that hasn't been called in the

longest time.



Alistair's strategy is to remove the number that's been in the memory the

longest time.



Example game:

*Turn*

*Called*

*number*



*Sindhu's*

*memory*

*Sindhu's*

*score*



*Alistair's*

*memory*



*Alistair's*

*score*

1

1

1

0

1

0

2

2

1,2

0

1,2

0

3

4

1,2,4

0

1,2,4

0

4

6

1,2,4,6

0

1,2,4,6

0

5

1

1,2,4,6

1

1,2,4,6

1

6

8

1,2,4,6,8

1

1,2,4,6,8

1

7

10

1,4,6,8,10

1

2,4,6,8,10

1

8

2

1,2,6,8,10

1

2,4,6,8,10

2

9

4

1,2,4,8,10

1

2,4,6,8,10

2

10

1

1,2,4,8,10

2

1,4,6,8,10

3



Denoting Sindhu's score by *S *and Alistair's score by *A*.



The game is for a total of 20 called numbers, with the property that all

numbers would be called equal number of times (2 times each across 20

call-outs).



Given a set of 20 called numbers in a sequence, identifiy the winner of
this game the earliest in the sequence.

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: check Similar array

2012-01-04 Thread shiv narayan
can't be use squares of no's as said by rahul patil as said in
previous comment??

On Jan 4, 10:57 am, atul anand  wrote:
> @sharad : after checking the link provided by u...it seem like complexity
> will be O(n^2) { not sure } + saurabh point is also valid.

-- 
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 group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: String passing

2012-01-04 Thread rahul patil
When u say char p[]="hello";

memory to array is allocated on stack and "hello" is written into that
array. so u can modify "hello" by saying p[0]= 'y';

=

when u say char *x="hello";

memory to x is allocated on stack, but string "hello" is placed in the read
only memory section(sometimes called as literal section)
and address to "hello" is stored in variable x. this type of string are
called as read only strings. so u can modify x, but not the contents of the
constant string "hello".

So x=p; // valid , modified variable on stack
but x[0]='z' // invalid, tried to modify the constant string


On Wed, Jan 4, 2012 at 1:07 PM, Arun Vishwanathan wrote:

> if instead of passing "hello" directly to function if we passed char array
> p then this would not show as an error right? and why is this so? is it due
> to the fact tat p array was not possibly allocated in the read only segment
> of memory and hence when passed it can be modified by function? so if const
> string is passed directly what causes the error?
>
>
> On Sat, Aug 27, 2011 at 11:28 AM, sagar pareek wrote:
>
>> @raj
>>
>> u already mentioned that if we write :-
>> char *p="hello";
>> p[0]='k'; // gives runtime error
>>
>>
>> so if we are passing arguments as
>>
>> modify(char a[],char *b)
>> {
>> .
>> .
>> }
>>
>> main()
>> {
>> .
>> .
>> modify("hello","hi");
>> .
>> .
>> }
>>
>>
>> then its actually
>> char arr[]="hello";
>> char *b="hi";
>>
>> so ofcourse now
>> b[0]='a'; // give u runtime error
>>
>> now u may be confuse about
>> arr[0]='a'; //gives runtime error
>>
>> here i would like to tell you that arr is char pointer not char array
>> you can check by yourself in :-   http://www.ideone.com/EQrjj
>>
>> On Sat, Aug 27, 2011 at 10:39 PM, raj kumar wrote:
>>
>>>
>>> "monsters are monsters"
>>>
>>>
>>>
>>> -- Forwarded message --
>>> From: raj kumar 
>>> Date: Sat, Aug 27, 2011 at 10:30 PM
>>> Subject: Re: [algogeeks] Re: String passing
>>> To: algogeeks@googlegroups.com
>>>
>>>
>>> can't understand what are you trying to say
>>>
>>> source
>>>
>>>  --
>>> 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 group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> **Regards
>> SAGAR PAREEK
>> COMPUTER SCIENCE AND ENGINEERING
>> NIT ALLAHABAD
>>
>>  --
>> 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 group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>  "People often say that motivation doesn't last. Well, neither does
> bathing - that's why we recommend it daily."
>
>  --
> 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 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 algogeeks@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: Modular arithmetic + Combinatorics

2012-01-04 Thread atul anand
@Dave : in your pseudo code for B(m,n)

you are not using m ... i guess there is a typo error.

this should be num[i]=m + 1 -i instead of this
num[i] = n + 1 - 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 group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.