Re: [algogeeks] Amazon Question

2011-03-03 Thread Manish Pathak
Explain @Param explain it..

On Thu, Mar 3, 2011 at 11:34 AM, preetika tyagi wrote:

> @Arpit - Can you please explain how would you solve it using binary search?
>
>
> On Wed, Mar 2, 2011 at 10:41 PM, Arpit Sood  wrote:
>
>> O(logn) binary search if there are no duplicates, else O(n)
>>
>>
>> On Thu, Mar 3, 2011 at 11:04 AM, Param10k  wrote:
>>
>>> There is a sorted array and you have to write a fn to find a number in
>>> the array which satisfies
>>>
>>> A[i] = i ; where A is the array and i is the index...
>>>
>>> - Param
>>> http://teknotron-param.blogspot.com/
>>>
>>> --
>>> 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,
>> Arpit Sood
>>
>>  --
>> 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.
>



-- 

Thanks and Regards,

Manish Pathak **
TimesJobs.com
Mo.  9015687266

-- 
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] [brain teaser ] 3march

2011-03-03 Thread Lavesh Rawat
*Split the Booty Problem Solution*
*
*
A pirate crew at the end of the day split the booty. The first pirate got
100 gold pieces, and 1/6 of the remaining booty. The second one got 200 gold
pieces, and 1/6 of the remaining booty. The third one got 300 gold pieces,
and 1/6 of the remaining booty. Ect. The last one only got, what if left
from the booty.
At the end, every pirate had the same ammount of gold pieces (from the
booty).
How many pirates were there, and how much was the booty.

Update Your Answers at : Click
Here

Solution:
Will be updated after 1 day


-- 

"Never explain yourself. Your friends don’t need it and
your enemies won’t believe it" .

-- 
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] [brain teaser ] 3march

2011-03-03 Thread rajul jain
2500 gold
5 pirates

Set the initial 2 pirates gold equal as follows:
x = total gold

100 + [(x-100)/6] = 200 + [(x - 200 - 100 - ((x-100)/6)/6]

Rearranging and solving:
x - 100 = 300 + x - [(x-100)/6]

And again:
0 = 400 - [(x-100)/6]

And again:
0 = 2400 - x + 100

Therefore x = 2500

Substitue this value into the equation for Pirate 1

On Thu, Mar 3, 2011 at 1:32 PM, Lavesh Rawat  wrote:

> *Split the Booty Problem Solution*
> *
> *
> A pirate crew at the end of the day split the booty. The first pirate got
> 100 gold pieces, and 1/6 of the remaining booty. The second one got 200 gold
> pieces, and 1/6 of the remaining booty. The third one got 300 gold pieces,
> and 1/6 of the remaining booty. Ect. The last one only got, what if left
> from the booty.
> At the end, every pirate had the same ammount of gold pieces (from the
> booty).
> How many pirates were there, and how much was the booty.
>
> Update Your Answers at : Click 
> Here
>
> Solution:
> Will be updated after 1 day
>
>
> --
>
> "Never explain yourself. Your friends don’t need it and
> your enemies won’t believe it" .
>
> --
> 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.



[algogeeks] brain teaser

2011-03-03 Thread freecoder
You are one of 20 prisoners on death row with the execution date set
for tomorrow.

Your king is a ruthless man who likes to toy with his people's
miseries. He comes to your cell today and tells you:

“I’m gonna give you prisoners a chance to go free tomorrow. You will
all stand in a row (queue) before the executioner and we will put a
hat on your head, either a red or a black one. Of course you will not
be able to see the color of your own hat; you will only be able to see
the prisoners in front of you with their hats on; you will not be
allowed to look back or communicate together in any way (talking,
touching.)

(The prisoner in the back will be able to see the 19 prisoners in
front of him
The one in front of him will be able to see 18…)

Starting with the last person in the row, the one who can see
everybody in front of him, he will be asked a simple question: WHAT IS
THE COLOR OF YOUR HAT?

He will be only allowed to answer “BLACK” or “RED”. If he says
anything else you will ALL be executed immediately.

If he guesses the right color of the hat on his head he is set free,
otherwise he is put to death. And we move on to the one in front of
him and ask him the same question and so on…

Well, good luck tomorrow, HA HA HA HA HA HA!”

Now since you all can communicate freely during the night, can you
find a way to guarantee the freedom of some prisoners tomorrow? How
many?

-- 
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] brain teaser

2011-03-03 Thread Manish Pathak
I think that the last person will tell the color of next front person of
him, that means next person will sure that his hat color will be color
,telling by back person.
thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and rest amy
or may not be...

if i am wrong ,tell me


On Thu, Mar 3, 2011 at 1:48 PM, freecoder  wrote:

> You are one of 20 prisoners on death row with the execution date set
> for tomorrow.
>
> Your king is a ruthless man who likes to toy with his people's
> miseries. He comes to your cell today and tells you:
>
> “I’m gonna give you prisoners a chance to go free tomorrow. You will
> all stand in a row (queue) before the executioner and we will put a
> hat on your head, either a red or a black one. Of course you will not
> be able to see the color of your own hat; you will only be able to see
> the prisoners in front of you with their hats on; you will not be
> allowed to look back or communicate together in any way (talking,
> touching.)
>
> (The prisoner in the back will be able to see the 19 prisoners in
> front of him
> The one in front of him will be able to see 18…)
>
> Starting with the last person in the row, the one who can see
> everybody in front of him, he will be asked a simple question: WHAT IS
> THE COLOR OF YOUR HAT?
>
> He will be only allowed to answer “BLACK” or “RED”. If he says
> anything else you will ALL be executed immediately.
>
> If he guesses the right color of the hat on his head he is set free,
> otherwise he is put to death. And we move on to the one in front of
> him and ask him the same question and so on…
>
> Well, good luck tomorrow, HA HA HA HA HA HA!”
>
> Now since you all can communicate freely during the night, can you
> find a way to guarantee the freedom of some prisoners tomorrow? How
> many?
>
> --
> 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.
>
>


-- 

Thanks and Regards,

Manish Pathak **
TimesJobs.com
manish.pat...@timesgroup.com
Mo.  9015687266

-- 
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] brain teaser

2011-03-03 Thread amit kumar
ya at least 10 can be easily freed

On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak  wrote:

> I think that the last person will tell the color of next front person of
> him, that means next person will sure that his hat color will be color
> ,telling by back person.
> thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and rest
> amy or may not be...
>
> if i am wrong ,tell me
>
>
>
> On Thu, Mar 3, 2011 at 1:48 PM, freecoder  wrote:
>
>> You are one of 20 prisoners on death row with the execution date set
>> for tomorrow.
>>
>> Your king is a ruthless man who likes to toy with his people's
>> miseries. He comes to your cell today and tells you:
>>
>> “I’m gonna give you prisoners a chance to go free tomorrow. You will
>> all stand in a row (queue) before the executioner and we will put a
>> hat on your head, either a red or a black one. Of course you will not
>> be able to see the color of your own hat; you will only be able to see
>> the prisoners in front of you with their hats on; you will not be
>> allowed to look back or communicate together in any way (talking,
>> touching.)
>>
>> (The prisoner in the back will be able to see the 19 prisoners in
>> front of him
>> The one in front of him will be able to see 18…)
>>
>> Starting with the last person in the row, the one who can see
>> everybody in front of him, he will be asked a simple question: WHAT IS
>> THE COLOR OF YOUR HAT?
>>
>> He will be only allowed to answer “BLACK” or “RED”. If he says
>> anything else you will ALL be executed immediately.
>>
>> If he guesses the right color of the hat on his head he is set free,
>> otherwise he is put to death. And we move on to the one in front of
>> him and ask him the same question and so on…
>>
>> Well, good luck tomorrow, HA HA HA HA HA HA!”
>>
>> Now since you all can communicate freely during the night, can you
>> find a way to guarantee the freedom of some prisoners tomorrow? How
>> many?
>>
>> --
>> 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.
>>
>>
>
>
> --
>
> Thanks and Regards,
>
> Manish Pathak **
> TimesJobs.com
> manish.pat...@timesgroup.com
> Mo.  9015687266
>
>
>  --
> 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] brain teaser

2011-03-03 Thread Naveen Kumar
http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle

On Thu, Mar 3, 2011 at 3:01 PM, amit kumar  wrote:

> ya at least 10 can be easily freed
>
>
> On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak wrote:
>
>> I think that the last person will tell the color of next front person of
>> him, that means next person will sure that his hat color will be color
>> ,telling by back person.
>> thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and rest
>> amy or may not be...
>>
>> if i am wrong ,tell me
>>
>>
>>
>> On Thu, Mar 3, 2011 at 1:48 PM, freecoder  wrote:
>>
>>> You are one of 20 prisoners on death row with the execution date set
>>> for tomorrow.
>>>
>>> Your king is a ruthless man who likes to toy with his people's
>>> miseries. He comes to your cell today and tells you:
>>>
>>> “I’m gonna give you prisoners a chance to go free tomorrow. You will
>>> all stand in a row (queue) before the executioner and we will put a
>>> hat on your head, either a red or a black one. Of course you will not
>>> be able to see the color of your own hat; you will only be able to see
>>> the prisoners in front of you with their hats on; you will not be
>>> allowed to look back or communicate together in any way (talking,
>>> touching.)
>>>
>>> (The prisoner in the back will be able to see the 19 prisoners in
>>> front of him
>>> The one in front of him will be able to see 18…)
>>>
>>> Starting with the last person in the row, the one who can see
>>> everybody in front of him, he will be asked a simple question: WHAT IS
>>> THE COLOR OF YOUR HAT?
>>>
>>> He will be only allowed to answer “BLACK” or “RED”. If he says
>>> anything else you will ALL be executed immediately.
>>>
>>> If he guesses the right color of the hat on his head he is set free,
>>> otherwise he is put to death. And we move on to the one in front of
>>> him and ask him the same question and so on…
>>>
>>> Well, good luck tomorrow, HA HA HA HA HA HA!”
>>>
>>> Now since you all can communicate freely during the night, can you
>>> find a way to guarantee the freedom of some prisoners tomorrow? How
>>> many?
>>>
>>> --
>>> 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.
>>>
>>>
>>
>>
>> --
>>
>> Thanks and Regards,
>>
>> Manish Pathak **
>> TimesJobs.com
>>  manish.pat...@timesgroup.com
>> Mo.  9015687266
>>
>>
>>  --
>> 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.
>



-- 
Cheers
Naveen Kumar

-- 
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] brain teaser

2011-03-03 Thread rajul jain
@naveen
but in this question don't know numbers of black and red hats like prison
and hat puzzle

On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar wrote:

> http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle
>
> On Thu, Mar 3, 2011 at 3:01 PM, amit kumar wrote:
>
>> ya at least 10 can be easily freed
>>
>>
>> On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak wrote:
>>
>>> I think that the last person will tell the color of next front person of
>>> him, that means next person will sure that his hat color will be color
>>> ,telling by back person.
>>> thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and rest
>>> amy or may not be...
>>>
>>> if i am wrong ,tell me
>>>
>>>
>>>
>>> On Thu, Mar 3, 2011 at 1:48 PM, freecoder wrote:
>>>
 You are one of 20 prisoners on death row with the execution date set
 for tomorrow.

 Your king is a ruthless man who likes to toy with his people's
 miseries. He comes to your cell today and tells you:

 “I’m gonna give you prisoners a chance to go free tomorrow. You will
 all stand in a row (queue) before the executioner and we will put a
 hat on your head, either a red or a black one. Of course you will not
 be able to see the color of your own hat; you will only be able to see
 the prisoners in front of you with their hats on; you will not be
 allowed to look back or communicate together in any way (talking,
 touching.)

 (The prisoner in the back will be able to see the 19 prisoners in
 front of him
 The one in front of him will be able to see 18…)

 Starting with the last person in the row, the one who can see
 everybody in front of him, he will be asked a simple question: WHAT IS
 THE COLOR OF YOUR HAT?

 He will be only allowed to answer “BLACK” or “RED”. If he says
 anything else you will ALL be executed immediately.

 If he guesses the right color of the hat on his head he is set free,
 otherwise he is put to death. And we move on to the one in front of
 him and ask him the same question and so on…

 Well, good luck tomorrow, HA HA HA HA HA HA!”

 Now since you all can communicate freely during the night, can you
 find a way to guarantee the freedom of some prisoners tomorrow? How
 many?

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


>>>
>>>
>>> --
>>>
>>> Thanks and Regards,
>>>
>>> Manish Pathak **
>>> TimesJobs.com
>>>  manish.pat...@timesgroup.com
>>> Mo.  9015687266
>>>
>>>
>>>  --
>>> 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.
>>
>
>
>
> --
> Cheers
> Naveen Kumar
>
> --
> 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] brain teaser

2011-03-03 Thread Naveen Kumar
There are many variants of this puzzle listed there.

checkout for "Ten-Hat Variant"

On Thu, Mar 3, 2011 at 3:32 PM, rajul jain  wrote:

> @naveen
> but in this question don't know numbers of black and red hats like prison
> and hat puzzle
>
>
> On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar 
> wrote:
>
>> http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle
>>
>> On Thu, Mar 3, 2011 at 3:01 PM, amit kumar wrote:
>>
>>> ya at least 10 can be easily freed
>>>
>>>
>>> On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak wrote:
>>>
 I think that the last person will tell the color of next front person of
 him, that means next person will sure that his hat color will be color
 ,telling by back person.
 thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and rest
 amy or may not be...

 if i am wrong ,tell me



 On Thu, Mar 3, 2011 at 1:48 PM, freecoder wrote:

> You are one of 20 prisoners on death row with the execution date set
> for tomorrow.
>
> Your king is a ruthless man who likes to toy with his people's
> miseries. He comes to your cell today and tells you:
>
> “I’m gonna give you prisoners a chance to go free tomorrow. You will
> all stand in a row (queue) before the executioner and we will put a
> hat on your head, either a red or a black one. Of course you will not
> be able to see the color of your own hat; you will only be able to see
> the prisoners in front of you with their hats on; you will not be
> allowed to look back or communicate together in any way (talking,
> touching.)
>
> (The prisoner in the back will be able to see the 19 prisoners in
> front of him
> The one in front of him will be able to see 18…)
>
> Starting with the last person in the row, the one who can see
> everybody in front of him, he will be asked a simple question: WHAT IS
> THE COLOR OF YOUR HAT?
>
> He will be only allowed to answer “BLACK” or “RED”. If he says
> anything else you will ALL be executed immediately.
>
> If he guesses the right color of the hat on his head he is set free,
> otherwise he is put to death. And we move on to the one in front of
> him and ask him the same question and so on…
>
> Well, good luck tomorrow, HA HA HA HA HA HA!”
>
> Now since you all can communicate freely during the night, can you
> find a way to guarantee the freedom of some prisoners tomorrow? How
> many?
>
> --
> 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.
>
>


 --

 Thanks and Regards,

 Manish Pathak **
 TimesJobs.com
  manish.pat...@timesgroup.com
 Mo.  9015687266


  --
 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.
>>>
>>
>>
>>
>> --
>> Cheers
>> Naveen Kumar
>>
>> --
>> 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.
>



-- 
Cheers
Naveen Kumar

-- 
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] brain teaser

2011-03-03 Thread rajul jain
@naveen you are right there is a variant similar to this problem but here
come to discuss solution to this problem.

On Thu, Mar 3, 2011 at 3:38 PM, Naveen Kumar wrote:

> There are many variants of this puzzle listed there.
>
> checkout for "Ten-Hat Variant"
>
>
> On Thu, Mar 3, 2011 at 3:32 PM, rajul jain  wrote:
>
>> @naveen
>> but in this question don't know numbers of black and red hats like prison
>> and hat puzzle
>>
>>
>> On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar 
>> wrote:
>>
>>> http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle
>>>
>>> On Thu, Mar 3, 2011 at 3:01 PM, amit kumar wrote:
>>>
 ya at least 10 can be easily freed


 On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak wrote:

> I think that the last person will tell the color of next front person
> of him, that means next person will sure that his hat color will be color
> ,telling by back person.
> thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and
> rest amy or may not be...
>
> if i am wrong ,tell me
>
>
>
> On Thu, Mar 3, 2011 at 1:48 PM, freecoder wrote:
>
>> You are one of 20 prisoners on death row with the execution date set
>> for tomorrow.
>>
>> Your king is a ruthless man who likes to toy with his people's
>> miseries. He comes to your cell today and tells you:
>>
>> “I’m gonna give you prisoners a chance to go free tomorrow. You will
>> all stand in a row (queue) before the executioner and we will put a
>> hat on your head, either a red or a black one. Of course you will not
>> be able to see the color of your own hat; you will only be able to see
>> the prisoners in front of you with their hats on; you will not be
>> allowed to look back or communicate together in any way (talking,
>> touching.)
>>
>> (The prisoner in the back will be able to see the 19 prisoners in
>> front of him
>> The one in front of him will be able to see 18…)
>>
>> Starting with the last person in the row, the one who can see
>> everybody in front of him, he will be asked a simple question: WHAT IS
>> THE COLOR OF YOUR HAT?
>>
>> He will be only allowed to answer “BLACK” or “RED”. If he says
>> anything else you will ALL be executed immediately.
>>
>> If he guesses the right color of the hat on his head he is set free,
>> otherwise he is put to death. And we move on to the one in front of
>> him and ask him the same question and so on…
>>
>> Well, good luck tomorrow, HA HA HA HA HA HA!”
>>
>> Now since you all can communicate freely during the night, can you
>> find a way to guarantee the freedom of some prisoners tomorrow? How
>> many?
>>
>> --
>> 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.
>>
>>
>
>
> --
>
> Thanks and Regards,
>
> Manish Pathak **
> TimesJobs.com
>  manish.pat...@timesgroup.com
> Mo.  9015687266
>
>
>  --
> 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.

>>>
>>>
>>>
>>> --
>>> Cheers
>>> Naveen Kumar
>>>
>>> --
>>> 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.
>>
>
>
>
> --
> Cheers
> Naveen Kumar
>
> --
> You received this m

[algogeeks] Re: brain teaser

2011-03-03 Thread Param10k
At d Max 1 person 'll die


-Param
http://teknotron-param.blogspot.com/

On Mar 3, 3:20 pm, rajul jain  wrote:
> @naveen you are right there is a variant similar to this problem but here
> come to discuss solution to this problem.
>
> On Thu, Mar 3, 2011 at 3:38 PM, Naveen Kumar 
> wrote:
>
>
>
>
>
>
>
> > There are many variants of this puzzle listed there.
>
> > checkout for "Ten-Hat Variant"
>
> > On Thu, Mar 3, 2011 at 3:32 PM, rajul jain  wrote:
>
> >> @naveen
> >> but in this question don't know numbers of black and red hats like prison
> >> and hat puzzle
>
> >> On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar 
> >> wrote:
>
> >>>http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle
>
> >>> On Thu, Mar 3, 2011 at 3:01 PM, amit kumar wrote:
>
>  ya at least 10 can be easily freed
>
>  On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak 
>  wrote:
>
> > I think that the last person will tell the color of next front person
> > of him, that means next person will sure that his hat color will be 
> > color
> > ,telling by back person.
> > thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and
> > rest amy or may not be...
>
> > if i am wrong ,tell me
>
> > On Thu, Mar 3, 2011 at 1:48 PM, freecoder wrote:
>
> >> You are one of 20 prisoners on death row with the execution date set
> >> for tomorrow.
>
> >> Your king is a ruthless man who likes to toy with his people's
> >> miseries. He comes to your cell today and tells you:
>
> >> “I’m gonna give you prisoners a chance to go free tomorrow. You will
> >> all stand in a row (queue) before the executioner and we will put a
> >> hat on your head, either a red or a black one. Of course you will not
> >> be able to see the color of your own hat; you will only be able to see
> >> the prisoners in front of you with their hats on; you will not be
> >> allowed to look back or communicate together in any way (talking,
> >> touching.)
>
> >> (The prisoner in the back will be able to see the 19 prisoners in
> >> front of him
> >> The one in front of him will be able to see 18…)
>
> >> Starting with the last person in the row, the one who can see
> >> everybody in front of him, he will be asked a simple question: WHAT IS
> >> THE COLOR OF YOUR HAT?
>
> >> He will be only allowed to answer “BLACK” or “RED”. If he says
> >> anything else you will ALL be executed immediately.
>
> >> If he guesses the right color of the hat on his head he is set free,
> >> otherwise he is put to death. And we move on to the one in front of
> >> him and ask him the same question and so on…
>
> >> Well, good luck tomorrow, HA HA HA HA HA HA!”
>
> >> Now since you all can communicate freely during the night, can you
> >> find a way to guarantee the freedom of some prisoners tomorrow? How
> >> many?
>
> >> --
> >> 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.
>
> > --
>
> > Thanks and Regards,
>
> > Manish Pathak **
> > TimesJobs.com
> >  manish.pat...@timesgroup.com
> > Mo.  9015687266
>
> >  --
> > 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.
>
> >>> --
> >>> Cheers
> >>> Naveen Kumar
>
> >>> --
> >>> 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...@googlegrou

Re: [algogeeks] Amazon Question

2011-03-03 Thread Ankit Sinha
Hi,

Here is the code to do this using Bsearch in o(logn) time.

int BsearchElemEqualIndex (int *a, int start, int end)
{
int mid = (((end - start) >> 1) + start);
if (a[mid] == mid)
return a[mid];
else if (a[mid] != mid)
{
if (mid == start || mid == end)
{
return -1;
}
else
{
BsearchElemEqualIndex (a, start, mid);
BsearchElemEqualIndex (a, mid + 1, end);
}
}
}

int _tmain(int argc, _TCHAR* argv[])
{
int a[SIZE] = {5,9,3,8,1,2,6,7};
int x = BsearchElemEqualIndex (a, 0, SIZE);
printf ("%d", x);
system ("PAUSE");
return 0;
}

Cheers,
Ankit!!!

On Thu, Mar 3, 2011 at 11:04 AM, Param10k  wrote:
> There is a sorted array and you have to write a fn to find a number in
> the array which satisfies
>
> A[i] = i ; where A is the array and i is the index...
>
> - Param
> http://teknotron-param.blogspot.com/
>
> --
> 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] Amazon Question

2011-03-03 Thread sukhmeet singh
what should be the answer for this:
if A={0,1,2,4,5}
0 or 1 or 2
On Thu, Mar 3, 2011 at 6:26 PM, Ankit Sinha  wrote:

> Hi,
>
> Here is the code to do this using Bsearch in o(logn) time.
>
> int BsearchElemEqualIndex (int *a, int start, int end)
> {
>int mid = (((end - start) >> 1) + start);
>if (a[mid] == mid)
>return a[mid];
>else if (a[mid] != mid)
>{
>if (mid == start || mid == end)
>{
>return -1;
>}
>else
>{
>BsearchElemEqualIndex (a, start, mid);
>BsearchElemEqualIndex (a, mid + 1, end);
>}
>}
> }
>
> int _tmain(int argc, _TCHAR* argv[])
> {
>int a[SIZE] = {5,9,3,8,1,2,6,7};
>int x = BsearchElemEqualIndex (a, 0, SIZE);
>printf ("%d", x);
>system ("PAUSE");
>return 0;
> }
>
> Cheers,
> Ankit!!!
>
> On Thu, Mar 3, 2011 at 11:04 AM, Param10k  wrote:
> > There is a sorted array and you have to write a fn to find a number in
> > the array which satisfies
> >
> > A[i] = i ; where A is the array and i is the index...
> >
> > - Param
> > http://teknotron-param.blogspot.com/
> >
> > --
> > 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] Amazon Question

2011-03-03 Thread Ankit Sinha
@sukhmeet, as per the question, there is a unique value which satisfy
a[i] = i in the array and written code captures that only. Else we
need to modify if we are interested in all such values which statisfy
the said condition. And also in that case looping around bsearch will
not be a good idea.. it will be better to go for simple loop in o(n)
time as every time mid calculation is also costly. I agreed to Arpit
view point and accordingly did coding as preetika needed as per arpit
comments.

Cheers!!
Ankit

On Thu, Mar 3, 2011 at 6:53 PM, sukhmeet singh  wrote:
> what should be the answer for this:
> if A={0,1,2,4,5}
> 0 or 1 or 2
> On Thu, Mar 3, 2011 at 6:26 PM, Ankit Sinha  wrote:
>>
>> Hi,
>>
>> Here is the code to do this using Bsearch in o(logn) time.
>>
>> int BsearchElemEqualIndex (int *a, int start, int end)
>> {
>>        int mid = (((end - start) >> 1) + start);
>>        if (a[mid] == mid)
>>                return a[mid];
>>        else if (a[mid] != mid)
>>        {
>>                if (mid == start || mid == end)
>>                {
>>                        return -1;
>>                }
>>                else
>>                {
>>                        BsearchElemEqualIndex (a, start, mid);
>>                        BsearchElemEqualIndex (a, mid + 1, end);
>>                }
>>        }
>> }
>>
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>>        int a[SIZE] = {5,9,3,8,1,2,6,7};
>>        int x = BsearchElemEqualIndex (a, 0, SIZE);
>>        printf ("%d", x);
>>        system ("PAUSE");
>>        return 0;
>> }
>>
>> Cheers,
>> Ankit!!!
>>
>> On Thu, Mar 3, 2011 at 11:04 AM, Param10k  wrote:
>> > There is a sorted array and you have to write a fn to find a number in
>> > the array which satisfies
>> >
>> > A[i] = i ; where A is the array and i is the index...
>> >
>> > - Param
>> > http://teknotron-param.blogspot.com/
>> >
>> > --
>> > 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] Amazon Question

2011-03-03 Thread jagannath prasad das
@ankit sinha:i dont think the algo u wrote is o(logn).its o(N) i guess

On Thu, Mar 3, 2011 at 7:05 PM, Ankit Sinha  wrote:

> @sukhmeet, as per the question, there is a unique value which satisfy
> a[i] = i in the array and written code captures that only. Else we
> need to modify if we are interested in all such values which statisfy
> the said condition. And also in that case looping around bsearch will
> not be a good idea.. it will be better to go for simple loop in o(n)
> time as every time mid calculation is also costly. I agreed to Arpit
> view point and accordingly did coding as preetika needed as per arpit
> comments.
>
> Cheers!!
> Ankit
>
> On Thu, Mar 3, 2011 at 6:53 PM, sukhmeet singh 
> wrote:
> > what should be the answer for this:
> > if A={0,1,2,4,5}
> > 0 or 1 or 2
> > On Thu, Mar 3, 2011 at 6:26 PM, Ankit Sinha  wrote:
> >>
> >> Hi,
> >>
> >> Here is the code to do this using Bsearch in o(logn) time.
> >>
> >> int BsearchElemEqualIndex (int *a, int start, int end)
> >> {
> >>int mid = (((end - start) >> 1) + start);
> >>if (a[mid] == mid)
> >>return a[mid];
> >>else if (a[mid] != mid)
> >>{
> >>if (mid == start || mid == end)
> >>{
> >>return -1;
> >>}
> >>else
> >>{
> >>BsearchElemEqualIndex (a, start, mid);
> >>BsearchElemEqualIndex (a, mid + 1, end);
> >>}
> >>}
> >> }
> >>
> >> int _tmain(int argc, _TCHAR* argv[])
> >> {
> >>int a[SIZE] = {5,9,3,8,1,2,6,7};
> >>int x = BsearchElemEqualIndex (a, 0, SIZE);
> >>printf ("%d", x);
> >>system ("PAUSE");
> >>return 0;
> >> }
> >>
> >> Cheers,
> >> Ankit!!!
> >>
> >> On Thu, Mar 3, 2011 at 11:04 AM, Param10k 
> wrote:
> >> > There is a sorted array and you have to write a fn to find a number in
> >> > the array which satisfies
> >> >
> >> > A[i] = i ; where A is the array and i is the index...
> >> >
> >> > - Param
> >> > http://teknotron-param.blogspot.com/
> >> >
> >> > --
> >> > 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.
>
>

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

2011-03-03 Thread nishaanth
@Ankit..your algm is O(n)...you should split the problem size to n/2 at
every stage...rather you are again computing both the subarrays..

Here is the correct code...

int BsearchElemEqualIndex (int *a, int start, int end)
{
   int mid = (((end - start) >> 1) + start);
   if (a[mid] == mid)
   return a[mid];
   else if (a[mid] != mid)
   {
   if (mid == start || mid == end)
   {
   return -1;
   }
   else
   {
  if(a[mid] < mid )
   BsearchElemEqualIndex (a, start, mid);

BsearchElemEqualIndex (a, mid + 1, end);
   }
   }
}

int _tmain(int argc, _TCHAR* argv[])
{
   int a[SIZE] = {5,9,3,8,1,2,6,7};
   int x = BsearchElemEqualIndex (a, 0, SIZE);
   printf ("%d", x);
   system ("PAUSE");
   return 0;
}

On Thu, Mar 3, 2011 at 7:20 PM, jagannath prasad das wrote:

> @ankit sinha:i dont think the algo u wrote is o(logn).its o(N) i guess
>
>
> On Thu, Mar 3, 2011 at 7:05 PM, Ankit Sinha  wrote:
>
>> @sukhmeet, as per the question, there is a unique value which satisfy
>> a[i] = i in the array and written code captures that only. Else we
>> need to modify if we are interested in all such values which statisfy
>> the said condition. And also in that case looping around bsearch will
>> not be a good idea.. it will be better to go for simple loop in o(n)
>> time as every time mid calculation is also costly. I agreed to Arpit
>> view point and accordingly did coding as preetika needed as per arpit
>> comments.
>>
>> Cheers!!
>> Ankit
>>
>> On Thu, Mar 3, 2011 at 6:53 PM, sukhmeet singh 
>> wrote:
>> > what should be the answer for this:
>> > if A={0,1,2,4,5}
>> > 0 or 1 or 2
>> > On Thu, Mar 3, 2011 at 6:26 PM, Ankit Sinha 
>> wrote:
>> >>
>> >> Hi,
>> >>
>> >> Here is the code to do this using Bsearch in o(logn) time.
>> >>
>> >> int BsearchElemEqualIndex (int *a, int start, int end)
>> >> {
>> >>int mid = (((end - start) >> 1) + start);
>> >>if (a[mid] == mid)
>> >>return a[mid];
>> >>else if (a[mid] != mid)
>> >>{
>> >>if (mid == start || mid == end)
>> >>{
>> >>return -1;
>> >>}
>> >>else
>> >>{
>> >>BsearchElemEqualIndex (a, start, mid);
>> >>BsearchElemEqualIndex (a, mid + 1, end);
>> >>}
>> >>}
>> >> }
>> >>
>> >> int _tmain(int argc, _TCHAR* argv[])
>> >> {
>> >>int a[SIZE] = {5,9,3,8,1,2,6,7};
>> >>int x = BsearchElemEqualIndex (a, 0, SIZE);
>> >>printf ("%d", x);
>> >>system ("PAUSE");
>> >>return 0;
>> >> }
>> >>
>> >> Cheers,
>> >> Ankit!!!
>> >>
>> >> On Thu, Mar 3, 2011 at 11:04 AM, Param10k 
>> wrote:
>> >> > There is a sorted array and you have to write a fn to find a number
>> in
>> >> > the array which satisfies
>> >> >
>> >> > A[i] = i ; where A is the array and i is the index...
>> >> >
>> >> > - Param
>> >> > http://teknotron-param.blogspot.com/
>> >> >
>> >> > --
>> >> > 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.
>>
>>
>  --
> 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...@g

Re: [algogeeks] Amazon Question

2011-03-03 Thread nishaanth
Ignore the previous post..there is a small error in the code..
@Ankit..your algm is O(n)...you should split the problem size to n/2 at
every stage...rather you are again computing both the subarrays..

Here is the correct code...

int BsearchElemEqualIndex (int *a, int start, int end)
{
   int mid = (((end - start) >> 1) + start);
   if (a[mid] == mid)
   return a[mid];
   else if (a[mid] != mid)
   {
   if (mid == start || mid == end)
   {
   return -1;
   }
   else
   {
  if(a[mid] < mid )
   BsearchElemEqualIndex (a, start, mid);
   else
   BsearchElemEqualIndex (a, mid + 1, end);
   }
   }
}

int _tmain(int argc, _TCHAR* argv[])
{
   int a[SIZE] = {5,9,3,8,1,2,6,7};
   int x = BsearchElemEqualIndex (a, 0, SIZE);
   printf ("%d", x);
   system ("PAUSE");
   return 0;
}
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

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

2011-03-03 Thread Gunjan Sharma
Still there is an error it should be
 if(a[mid] > mid )
   BsearchElemEqualIndex (a, start, mid);
   else
   BsearchElemEqualIndex (a, mid + 1, end);
correct me if I am wrong

On Thu, Mar 3, 2011 at 7:33 PM, nishaanth  wrote:

> Ignore the previous post..there is a small error in the code..
>  @Ankit..your algm is O(n)...you should split the problem size to n/2 at
> every stage...rather you are again computing both the subarrays..
>
> Here is the correct code...
>
> int BsearchElemEqualIndex (int *a, int start, int end)
> {
>int mid = (((end - start) >> 1) + start);
>if (a[mid] == mid)
>return a[mid];
>else if (a[mid] != mid)
>{
>if (mid == start || mid == end)
>{
>return -1;
>}
>else
>{
>   if(a[mid] < mid )
>BsearchElemEqualIndex (a, start, mid);
>else
>BsearchElemEqualIndex (a, mid + 1, end);
>}
>}
> }
>
> int _tmain(int argc, _TCHAR* argv[])
> {
>int a[SIZE] = {5,9,3,8,1,2,6,7};
>int x = BsearchElemEqualIndex (a, 0, SIZE);
>printf ("%d", x);
>system ("PAUSE");
>return 0;
> }
> S.Nishaanth,
> Computer Science and engineering,
> IIT Madras.
>
> --
> 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
Gunjan Sharma
Chairman IEEE Students Chapter IIT Roorkee
B.Tech IV year CSE

Contact No- +91 9997767077

-- 
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: Robot Moving on The Maze..Need All possible Path

2011-03-03 Thread bittu
both DP & Catalan Number solve this

1st Approach Catalan Number

(For clarity, we will solve this part assuming an X*Y Matrix)
Each path has (X-1)+(Y-1) steps. Imagine the following paths:

X X Y Y X (move right -> right -> down -> down -> right)
X Y X Y X (move right -> down -> right -> down -> right)
...& so on

Each path can be fully represented by the moves at which we move
right. That is, if I were to ask you which path you took, you could
simply say “I moved right on step 3 and 4.”
Since you must always move right X-1 times, and you have X-1 + Y-1
total steps, you have to pick X-1 times to move right out of X-1+Y-1
choices. Thus, there are C(X-1, X-1+Y-1) paths (e.g., X-1+Y-1 choose
X-1):

(X-1 + Y-1)! / ((X-1)! * (Y-1)!)..Hope This Equation Clear to Every1

which is nothing but C(2n-2,n-1)  Catalan Number


2nd Approach

DP(Always Best)

A robot can take path (N,M) from either (N-1,M) or (N,M-1)
if N and M is 0, its the beginning so return 0.
if N or M is 0, we can get there in 1 path.

We call paths(N,M) with s[][] initialized to -1.

int paths(int i,int j)
{
if(!(i||j)) //means we either can go down or right  path as only 1 is
zero
return 1;

if((i&&j))/// no path exist if both are zero
return 0;

if(s[i][j] != -1)
return s[i][j];

s[i][j] = paths(i-1,j) + paths(i,j-1);

return s[i][j];
}


I thinks We All Have Done With Thread. Still if Some has Doubt or
Found Anything Wrong Please Let me Know


Thanks & Regards
Shashank Mani >>"The Best Way to Escape From The Problem is Solve It"
Computer Science & Engineering
Birla Institute of Technology,Mesra

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

2011-03-03 Thread Ankit Sinha
@Gunjan & Nishanth, yes, you both are right. I just missed the basics
in dividing it in n/2 logically for each call.

Thanks,
Ankit!!

On Thu, Mar 3, 2011 at 7:39 PM, Gunjan Sharma  wrote:
> Still there is an error it should be
>  if(a[mid] > mid )
>                        BsearchElemEqualIndex (a, start, mid);
>                        else
>                            BsearchElemEqualIndex (a, mid + 1, end);
> correct me if I am wrong
> On Thu, Mar 3, 2011 at 7:33 PM, nishaanth  wrote:
>>
>> Ignore the previous post..there is a small error in the code..
>> @Ankit..your algm is O(n)...you should split the problem size to n/2 at
>> every stage...rather you are again computing both the subarrays..
>> Here is the correct code...
>> int BsearchElemEqualIndex (int *a, int start, int end)
>> {
>>        int mid = (((end - start) >> 1) + start);
>>        if (a[mid] == mid)
>>                return a[mid];
>>        else if (a[mid] != mid)
>>        {
>>                if (mid == start || mid == end)
>>                {
>>                        return -1;
>>                }
>>                else
>>                {
>>                       if(a[mid] < mid )
>>                        BsearchElemEqualIndex (a, start, mid);
>>                        else
>>                            BsearchElemEqualIndex (a, mid + 1, end);
>>                }
>>        }
>> }
>>
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>>        int a[SIZE] = {5,9,3,8,1,2,6,7};
>>        int x = BsearchElemEqualIndex (a, 0, SIZE);
>>        printf ("%d", x);
>>        system ("PAUSE");
>>        return 0;
>> }
>> S.Nishaanth,
>> Computer Science and engineering,
>> IIT Madras.
>>
>> --
>> 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
> Gunjan Sharma
> Chairman IEEE Students Chapter IIT Roorkee
> B.Tech IV year CSE
> Contact No- +91 9997767077
>
> --
> 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] Amazon Question

2011-03-03 Thread rajul jain
i think he is wrong bcoz this array in not sorted one.
so solution of Ankit is right.

On Thu, Mar 3, 2011 at 7:33 PM, nishaanth  wrote:

> Ignore the previous post..there is a small error in the code..
> @Ankit..your algm is O(n)...you should split the problem size to n/2 at
> every stage...rather you are again computing both the subarrays..
>
> Here is the correct code...
>
> int BsearchElemEqualIndex (int *a, int start, int end)
> {
>int mid = (((end - start) >> 1) + start);
>if (a[mid] == mid)
>return a[mid];
>else if (a[mid] != mid)
>{
>if (mid == start || mid == end)
>{
>return -1;
>}
>else
>{
>   if(a[mid] < mid )
>BsearchElemEqualIndex (a, start, mid);
>else
>BsearchElemEqualIndex (a, mid + 1, end);
>}
>}
> }
>
> int _tmain(int argc, _TCHAR* argv[])
> {
>int a[SIZE] = {5,9,3,8,1,2,6,7};
>int x = BsearchElemEqualIndex (a, 0, SIZE);
>printf ("%d", x);
>system ("PAUSE");
>return 0;
> }
> S.Nishaanth,
> Computer Science and engineering,
> IIT Madras.
>
> --
> 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] Amazon Question

2011-03-03 Thread rajul jain
@ankit  they both(gunjan & nishanth) are right in term of complexity but
their solution is not correct ...
tell me if i am wrong

On Thu, Mar 3, 2011 at 8:15 PM, Ankit Sinha  wrote:

> @Gunjan & Nishanth, yes, you both are right. I just missed the basics
> in dividing it in n/2 logically for each call.
>
> Thanks,
> Ankit!!
>
> On Thu, Mar 3, 2011 at 7:39 PM, Gunjan Sharma 
> wrote:
> > Still there is an error it should be
> >  if(a[mid] > mid )
> >BsearchElemEqualIndex (a, start, mid);
> >else
> >BsearchElemEqualIndex (a, mid + 1, end);
> > correct me if I am wrong
> > On Thu, Mar 3, 2011 at 7:33 PM, nishaanth  wrote:
> >>
> >> Ignore the previous post..there is a small error in the code..
> >> @Ankit..your algm is O(n)...you should split the problem size to n/2 at
> >> every stage...rather you are again computing both the subarrays..
> >> Here is the correct code...
> >> int BsearchElemEqualIndex (int *a, int start, int end)
> >> {
> >>int mid = (((end - start) >> 1) + start);
> >>if (a[mid] == mid)
> >>return a[mid];
> >>else if (a[mid] != mid)
> >>{
> >>if (mid == start || mid == end)
> >>{
> >>return -1;
> >>}
> >>else
> >>{
> >>   if(a[mid] < mid )
> >>BsearchElemEqualIndex (a, start, mid);
> >>else
> >>BsearchElemEqualIndex (a, mid + 1, end);
> >>}
> >>}
> >> }
> >>
> >> int _tmain(int argc, _TCHAR* argv[])
> >> {
> >>int a[SIZE] = {5,9,3,8,1,2,6,7};
> >>int x = BsearchElemEqualIndex (a, 0, SIZE);
> >>printf ("%d", x);
> >>system ("PAUSE");
> >>return 0;
> >> }
> >> S.Nishaanth,
> >> Computer Science and engineering,
> >> IIT Madras.
> >>
> >> --
> >> 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
> > Gunjan Sharma
> > Chairman IEEE Students Chapter IIT Roorkee
> > B.Tech IV year CSE
> > Contact No- +91 9997767077
> >
> > --
> > 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: brain teaser

2011-03-03 Thread rajul jain
@param But how can u prove that.

On Thu, Mar 3, 2011 at 5:16 PM, Param10k  wrote:

> At d Max 1 person 'll die
>
>
> -Param
> http://teknotron-param.blogspot.com/
>
> On Mar 3, 3:20 pm, rajul jain  wrote:
> > @naveen you are right there is a variant similar to this problem but here
> > come to discuss solution to this problem.
> >
> > On Thu, Mar 3, 2011 at 3:38 PM, Naveen Kumar  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > There are many variants of this puzzle listed there.
> >
> > > checkout for "Ten-Hat Variant"
> >
> > > On Thu, Mar 3, 2011 at 3:32 PM, rajul jain 
> wrote:
> >
> > >> @naveen
> > >> but in this question don't know numbers of black and red hats like
> prison
> > >> and hat puzzle
> >
> > >> On Thu, Mar 3, 2011 at 3:25 PM, Naveen Kumar <
> naveenkumarve...@gmail.com>wrote:
> >
> > >>>http://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle
> >
> > >>> On Thu, Mar 3, 2011 at 3:01 PM, amit kumar  >wrote:
> >
> >  ya at least 10 can be easily freed
> >
> >  On Thu, Mar 3, 2011 at 2:18 PM, Manish Pathak  >wrote:
> >
> > > I think that the last person will tell the color of next front
> person
> > > of him, that means next person will sure that his hat color will be
> color
> > > ,telling by back person.
> > > thus person 19 ,17,15,13,11,9,7,5,3,1 th position will get free,and
> > > rest amy or may not be...
> >
> > > if i am wrong ,tell me
> >
> > > On Thu, Mar 3, 2011 at 1:48 PM, freecoder  >wrote:
> >
> > >> You are one of 20 prisoners on death row with the execution date
> set
> > >> for tomorrow.
> >
> > >> Your king is a ruthless man who likes to toy with his people's
> > >> miseries. He comes to your cell today and tells you:
> >
> > >> “I’m gonna give you prisoners a chance to go free tomorrow. You
> will
> > >> all stand in a row (queue) before the executioner and we will put
> a
> > >> hat on your head, either a red or a black one. Of course you will
> not
> > >> be able to see the color of your own hat; you will only be able to
> see
> > >> the prisoners in front of you with their hats on; you will not be
> > >> allowed to look back or communicate together in any way (talking,
> > >> touching.)
> >
> > >> (The prisoner in the back will be able to see the 19 prisoners in
> > >> front of him
> > >> The one in front of him will be able to see 18…)
> >
> > >> Starting with the last person in the row, the one who can see
> > >> everybody in front of him, he will be asked a simple question:
> WHAT IS
> > >> THE COLOR OF YOUR HAT?
> >
> > >> He will be only allowed to answer “BLACK” or “RED”. If he says
> > >> anything else you will ALL be executed immediately.
> >
> > >> If he guesses the right color of the hat on his head he is set
> free,
> > >> otherwise he is put to death. And we move on to the one in front
> of
> > >> him and ask him the same question and so on…
> >
> > >> Well, good luck tomorrow, HA HA HA HA HA HA!”
> >
> > >> Now since you all can communicate freely during the night, can you
> > >> find a way to guarantee the freedom of some prisoners tomorrow?
> How
> > >> many?
> >
> > >> --
> > >> 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.
> >
> > > --
> >
> > > Thanks and Regards,
> >
> > > Manish Pathak **
> > > TimesJobs.com
> > >  manish.pat...@timesgroup.com
> > > Mo.  9015687266
> >
> > >  --
> > > 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.
> >
> > >>> --
> > >>> Cheers
> > >>> Naveen Kumar
> >
> > >>> --
> > >>> 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.

Re: [algogeeks] Amazon Question

2011-03-03 Thread Ankit Sinha
@rahul, they are right as binary search is made on sorted array only.
think of array as
0,2,3,8, 10, 12, 14., 15. here a[mid ] = 10 > mid(4) hence next search
should happen between 0 till 4 subarrray.. In my code the input array
is also not correct as it is not a sorted array and that's why I made
a mistake in writing the code as well. Anyways we are clear and
concluded the code as final as below

int BsearchElemEqualIndex (int *a, int start, int end)
{
int mid = (((end - start) >> 1) + start);
if (a[mid] == mid)
return a[mid];
else if (a[mid] != mid)
{
if (mid == start || mid == end)
{
return -1;
}
else
{
if(a[mid] > mid )
BsearchElemEqualIndex (a, start, mid);
else
BsearchElemEqualIndex (a, mid + 1, end);
}
}
}

int _tmain(int argc, _TCHAR* argv[])
{
int a[SIZE] = {5,9,3,8,1,2,6,7};
int x = BsearchElemEqualIndex (a, 0, SIZE);
printf ("%d", x);
system ("PAUSE");
return 0;
}

On Thu, Mar 3, 2011 at 8:15 PM, rajul jain  wrote:
> i think he is wrong bcoz this array in not sorted one.
> so solution of Ankit is right.
>
> On Thu, Mar 3, 2011 at 7:33 PM, nishaanth  wrote:
>>
>> Ignore the previous post..there is a small error in the code..
>> @Ankit..your algm is O(n)...you should split the problem size to n/2 at
>> every stage...rather you are again computing both the subarrays..
>> Here is the correct code...
>> int BsearchElemEqualIndex (int *a, int start, int end)
>> {
>>        int mid = (((end - start) >> 1) + start);
>>        if (a[mid] == mid)
>>                return a[mid];
>>        else if (a[mid] != mid)
>>        {
>>                if (mid == start || mid == end)
>>                {
>>                        return -1;
>>                }
>>                else
>>                {
>>                       if(a[mid] < mid )
>>                        BsearchElemEqualIndex (a, start, mid);
>>                        else
>>                            BsearchElemEqualIndex (a, mid + 1, end);
>>                }
>>        }
>> }
>>
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>>        int a[SIZE] = {5,9,3,8,1,2,6,7};
>>        int x = BsearchElemEqualIndex (a, 0, SIZE);
>>        printf ("%d", x);
>>        system ("PAUSE");
>>        return 0;
>> }
>> S.Nishaanth,
>> Computer Science and engineering,
>> IIT Madras.
>>
>> --
>> 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] Amazon Question

2011-03-03 Thread Ankit Sinha
It is funny but right input is as mentioned earlier to rahul. 0,2,3,8,
10, 12, 14., 15 :).. Sorry for unnecessarily flooding your mail
accounts. Please ignore previous post

thanks,
ankit!!

On Thu, Mar 3, 2011 at 8:15 PM, rajul jain  wrote:
> i think he is wrong bcoz this array in not sorted one.
> so solution of Ankit is right.
>
> On Thu, Mar 3, 2011 at 7:33 PM, nishaanth  wrote:
>>
>> Ignore the previous post..there is a small error in the code..
>> @Ankit..your algm is O(n)...you should split the problem size to n/2 at
>> every stage...rather you are again computing both the subarrays..
>> Here is the correct code...
>> int BsearchElemEqualIndex (int *a, int start, int end)
>> {
>>        int mid = (((end - start) >> 1) + start);
>>        if (a[mid] == mid)
>>                return a[mid];
>>        else if (a[mid] != mid)
>>        {
>>                if (mid == start || mid == end)
>>                {
>>                        return -1;
>>                }
>>                else
>>                {
>>                       if(a[mid] < mid )
>>                        BsearchElemEqualIndex (a, start, mid);
>>                        else
>>                            BsearchElemEqualIndex (a, mid + 1, end);
>>                }
>>        }
>> }
>>
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>>        int a[SIZE] = {5,9,3,8,1,2,6,7};
>>        int x = BsearchElemEqualIndex (a, 0, SIZE);
>>        printf ("%d", x);
>>        system ("PAUSE");
>>        return 0;
>> }
>> S.Nishaanth,
>> Computer Science and engineering,
>> IIT Madras.
>>
>> --
>> 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.



[algogeeks] Re: Amazon Question

2011-03-03 Thread Vipin Agrawal
take an example

3 3 3 5 5 5 7 8

I think this would fail

On Mar 3, 8:22 pm, Ankit Sinha  wrote:
> It is funny but right input is as mentioned earlier to rahul. 0,2,3,8,
> 10, 12, 14., 15 :).. Sorry for unnecessarily flooding your mail
> accounts. Please ignore previous post
>
> thanks,
> ankit!!
>
> On Thu, Mar 3, 2011 at 8:15 PM, rajul jain  wrote:
> > i think he is wrong bcoz this array in not sorted one.
> > so solution of Ankit is right.
>
> > On Thu, Mar 3, 2011 at 7:33 PM, nishaanth  wrote:
>
> >> Ignore the previous post..there is a small error in the code..
> >> @Ankit..your algm is O(n)...you should split the problem size to n/2 at
> >> every stage...rather you are again computing both the subarrays..
> >> Here is the correct code...
> >> int BsearchElemEqualIndex (int *a, int start, int end)
> >> {
> >>        int mid = (((end - start) >> 1) + start);
> >>        if (a[mid] == mid)
> >>                return a[mid];
> >>        else if (a[mid] != mid)
> >>        {
> >>                if (mid == start || mid == end)
> >>                {
> >>                        return -1;
> >>                }
> >>                else
> >>                {
> >>                       if(a[mid] < mid )
> >>                        BsearchElemEqualIndex (a, start, mid);
> >>                        else
> >>                            BsearchElemEqualIndex (a, mid + 1, end);
> >>                }
> >>        }
> >> }
>
> >> int _tmain(int argc, _TCHAR* argv[])
> >> {
> >>        int a[SIZE] = {5,9,3,8,1,2,6,7};
> >>        int x = BsearchElemEqualIndex (a, 0, SIZE);
> >>        printf ("%d", x);
> >>        system ("PAUSE");
> >>        return 0;
> >> }
> >> S.Nishaanth,
> >> Computer Science and engineering,
> >> IIT Madras.
>
> >> --
> >> 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: Robot Moving on The Maze..Need All possible Path

2011-03-03 Thread sunny agrawal
which is nothing but C(2n-2,n-1)  Catalan Number 
i don't think so??

for a n*n grid answer is 2n!/n!n!
but catalan number gives ans as 2n!/(n+1)!n!


On Thu, Mar 3, 2011 at 8:12 PM, bittu  wrote:

> both DP & Catalan Number solve this
>
> 1st Approach Catalan Number
>
> (For clarity, we will solve this part assuming an X*Y Matrix)
> Each path has (X-1)+(Y-1) steps. Imagine the following paths:
>
> X X Y Y X (move right -> right -> down -> down -> right)
> X Y X Y X (move right -> down -> right -> down -> right)
> ...& so on
>
> Each path can be fully represented by the moves at which we move
> right. That is, if I were to ask you which path you took, you could
> simply say “I moved right on step 3 and 4.”
> Since you must always move right X-1 times, and you have X-1 + Y-1
> total steps, you have to pick X-1 times to move right out of X-1+Y-1
> choices. Thus, there are C(X-1, X-1+Y-1) paths (e.g., X-1+Y-1 choose
> X-1):
>
> (X-1 + Y-1)! / ((X-1)! * (Y-1)!)..Hope This Equation Clear to Every1
>
> which is nothing but C(2n-2,n-1)  Catalan Number
>
>
> 2nd Approach
>
> DP(Always Best)
>
> A robot can take path (N,M) from either (N-1,M) or (N,M-1)
> if N and M is 0, its the beginning so return 0.
> if N or M is 0, we can get there in 1 path.
>
> We call paths(N,M) with s[][] initialized to -1.
>
> int paths(int i,int j)
> {
> if(!(i||j)) //means we either can go down or right  path as only 1 is
> zero
> return 1;
>
> if((i&&j))/// no path exist if both are zero
> return 0;
>
> if(s[i][j] != -1)
> return s[i][j];
>
> s[i][j] = paths(i-1,j) + paths(i,j-1);
>
> return s[i][j];
> }
>
>
> I thinks We All Have Done With Thread. Still if Some has Doubt or
> Found Anything Wrong Please Let me Know
>
>
> Thanks & Regards
> Shashank Mani >>"The Best Way to Escape From The Problem is Solve It"
> Computer Science & Engineering
> Birla Institute of Technology,Mesra
>
> --
> 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.
>
>


-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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: brain teaser

2011-03-03 Thread Don
They agree on the following plan:

The prisoner at the back of the line counts up the number of red hats
he sees. If the number is odd, he says "Red". If it is even, he says
"Black".

Now the 19th prisoner can count the red hats he sees. He can deduce
what color his hat must be to make the total odd or even, as indicated
by the previous prisoner.

Each prisoner in line must keep track of the current state, odd or
even, which changes each time someone behind him indicates having a
red hat.

Don

On Mar 3, 2:18 am, freecoder  wrote:
> You are one of 20 prisoners on death row with the execution date set
> for tomorrow.
>
> Your king is a ruthless man who likes to toy with his people's
> miseries. He comes to your cell today and tells you:
>
> “I’m gonna give you prisoners a chance to go free tomorrow. You will
> all stand in a row (queue) before the executioner and we will put a
> hat on your head, either a red or a black one. Of course you will not
> be able to see the color of your own hat; you will only be able to see
> the prisoners in front of you with their hats on; you will not be
> allowed to look back or communicate together in any way (talking,
> touching.)
>
> (The prisoner in the back will be able to see the 19 prisoners in
> front of him
> The one in front of him will be able to see 18…)
>
> Starting with the last person in the row, the one who can see
> everybody in front of him, he will be asked a simple question: WHAT IS
> THE COLOR OF YOUR HAT?
>
> He will be only allowed to answer “BLACK” or “RED”. If he says
> anything else you will ALL be executed immediately.
>
> If he guesses the right color of the hat on his head he is set free,
> otherwise he is put to death. And we move on to the one in front of
> him and ask him the same question and so on…
>
> Well, good luck tomorrow, HA HA HA HA HA HA!”
>
> Now since you all can communicate freely during the night, can you
> find a way to guarantee the freedom of some prisoners tomorrow? How
> many?

-- 
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: brain teaser

2011-03-03 Thread Dave
I have a way to save 19. Let each prisoner have his own private
variable C, which he initializes to RED if he sees an odd number of
red hats, or to BLACK if he sees an even number of red hats. The last
man in the row announces his C. Every time someone announces the color
RED, everyone ahead of him flips his C to the other color. In turn,
each remaining man announces his C.

Dave

On Mar 3, 2:18 am, freecoder  wrote:
> You are one of 20 prisoners on death row with the execution date set
> for tomorrow.
>
> Your king is a ruthless man who likes to toy with his people's
> miseries. He comes to your cell today and tells you:
>
> “I’m gonna give you prisoners a chance to go free tomorrow. You will
> all stand in a row (queue) before the executioner and we will put a
> hat on your head, either a red or a black one. Of course you will not
> be able to see the color of your own hat; you will only be able to see
> the prisoners in front of you with their hats on; you will not be
> allowed to look back or communicate together in any way (talking,
> touching.)
>
> (The prisoner in the back will be able to see the 19 prisoners in
> front of him
> The one in front of him will be able to see 18…)
>
> Starting with the last person in the row, the one who can see
> everybody in front of him, he will be asked a simple question: WHAT IS
> THE COLOR OF YOUR HAT?
>
> He will be only allowed to answer “BLACK” or “RED”. If he says
> anything else you will ALL be executed immediately.
>
> If he guesses the right color of the hat on his head he is set free,
> otherwise he is put to death. And we move on to the one in front of
> him and ask him the same question and so on…
>
> Well, good luck tomorrow, HA HA HA HA HA HA!”
>
> Now since you all can communicate freely during the night, can you
> find a way to guarantee the freedom of some prisoners tomorrow? How
> many?

-- 
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: Amazon Question

2011-03-03 Thread sukhmeet singh
he already  pointed out that  there are no repetations..!!

On Thu, Mar 3, 2011 at 9:40 PM, Vipin Agrawal wrote:

> take an example
>
> 3 3 3 5 5 5 7 8
>
> I think this would fail
>
> On Mar 3, 8:22 pm, Ankit Sinha  wrote:
> > It is funny but right input is as mentioned earlier to rahul. 0,2,3,8,
> > 10, 12, 14., 15 :).. Sorry for unnecessarily flooding your mail
> > accounts. Please ignore previous post
> >
> > thanks,
> > ankit!!
> >
> > On Thu, Mar 3, 2011 at 8:15 PM, rajul jain 
> wrote:
> > > i think he is wrong bcoz this array in not sorted one.
> > > so solution of Ankit is right.
> >
> > > On Thu, Mar 3, 2011 at 7:33 PM, nishaanth 
> wrote:
> >
> > >> Ignore the previous post..there is a small error in the code..
> > >> @Ankit..your algm is O(n)...you should split the problem size to n/2
> at
> > >> every stage...rather you are again computing both the subarrays..
> > >> Here is the correct code...
> > >> int BsearchElemEqualIndex (int *a, int start, int end)
> > >> {
> > >>int mid = (((end - start) >> 1) + start);
> > >>if (a[mid] == mid)
> > >>return a[mid];
> > >>else if (a[mid] != mid)
> > >>{
> > >>if (mid == start || mid == end)
> > >>{
> > >>return -1;
> > >>}
> > >>else
> > >>{
> > >>   if(a[mid] < mid )
> > >>BsearchElemEqualIndex (a, start, mid);
> > >>else
> > >>BsearchElemEqualIndex (a, mid + 1, end);
> > >>}
> > >>}
> > >> }
> >
> > >> int _tmain(int argc, _TCHAR* argv[])
> > >> {
> > >>int a[SIZE] = {5,9,3,8,1,2,6,7};
> > >>int x = BsearchElemEqualIndex (a, 0, SIZE);
> > >>printf ("%d", x);
> > >>system ("PAUSE");
> > >>return 0;
> > >> }
> > >> S.Nishaanth,
> > >> Computer Science and engineering,
> > >> IIT Madras.
> >
> > >> --
> > >> 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.



[algogeeks] spoj problem - INFINITY

2011-03-03 Thread Vishnutej
I dunno y dis code isnt working.

#include
#include
using namespace std;
int main()
{
cout<::infinity();
}


Thnx in advance.


-- 
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] spoj problem - INFINITY

2011-03-03 Thread D.N.Vishwakarma@IITR
*this code is perfectly working . use gcc based compiler
*
On Thu, Mar 3, 2011 at 11:34 PM, Vishnutej
wrote:

> I dunno y dis code isnt working.
>
> #include
> #include
> using namespace std;
> int main()
> {
> cout<::infinity();
> }
>
>
> Thnx in advance.
>
>
> --
> 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.
>
>


-- 
*Deoki Nandan Vishwakarma
IITR MCA
Mathematics Department
*

-- 
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: Amazon Question

2011-03-03 Thread nishaanth
@Gunjani made a mistake...u r right...but there is one more hidden
assumption that the numbers are positive integers.

On Thu, Mar 3, 2011 at 10:57 PM, sukhmeet singh wrote:

> he already  pointed out that  there are no repetations..!!
>
>
> On Thu, Mar 3, 2011 at 9:40 PM, Vipin Agrawal wrote:
>
>> take an example
>>
>> 3 3 3 5 5 5 7 8
>>
>> I think this would fail
>>
>> On Mar 3, 8:22 pm, Ankit Sinha  wrote:
>> > It is funny but right input is as mentioned earlier to rahul. 0,2,3,8,
>> > 10, 12, 14., 15 :).. Sorry for unnecessarily flooding your mail
>> > accounts. Please ignore previous post
>> >
>> > thanks,
>> > ankit!!
>> >
>> > On Thu, Mar 3, 2011 at 8:15 PM, rajul jain 
>> wrote:
>> > > i think he is wrong bcoz this array in not sorted one.
>> > > so solution of Ankit is right.
>> >
>> > > On Thu, Mar 3, 2011 at 7:33 PM, nishaanth 
>> wrote:
>> >
>> > >> Ignore the previous post..there is a small error in the code..
>> > >> @Ankit..your algm is O(n)...you should split the problem size to n/2
>> at
>> > >> every stage...rather you are again computing both the subarrays..
>> > >> Here is the correct code...
>> > >> int BsearchElemEqualIndex (int *a, int start, int end)
>> > >> {
>> > >>int mid = (((end - start) >> 1) + start);
>> > >>if (a[mid] == mid)
>> > >>return a[mid];
>> > >>else if (a[mid] != mid)
>> > >>{
>> > >>if (mid == start || mid == end)
>> > >>{
>> > >>return -1;
>> > >>}
>> > >>else
>> > >>{
>> > >>   if(a[mid] < mid )
>> > >>BsearchElemEqualIndex (a, start, mid);
>> > >>else
>> > >>BsearchElemEqualIndex (a, mid + 1, end);
>> > >>}
>> > >>}
>> > >> }
>> >
>> > >> int _tmain(int argc, _TCHAR* argv[])
>> > >> {
>> > >>int a[SIZE] = {5,9,3,8,1,2,6,7};
>> > >>int x = BsearchElemEqualIndex (a, 0, SIZE);
>> > >>printf ("%d", x);
>> > >>system ("PAUSE");
>> > >>return 0;
>> > >> }
>> > >> S.Nishaanth,
>> > >> Computer Science and engineering,
>> > >> IIT Madras.
>> >
>> > >> --
>> > >> 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.
>



-- 
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

-- 
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] Missing Number in New Way Please Read Question Carefully..

2011-03-03 Thread nishaanth
Find XOR from 1 to n...takes O(n)  ans = X1

Now fetch individual bits from array elements...again take xor...takes O(n)
 ans= X2

result is  X1 xor X2

On Wed, Mar 2, 2011 at 1:44 AM, bittu  wrote:

> An array A[1...n] contains all the integers from 0 to n except for one
> number which is missing. In this problem, we cannot access an entire
> integer in A with a single operation.
> The elements of A are represented in binary, and the only operation we
> can use to access them is “fetch the jth bit of A[i]”, which takes
> constant time. Write code to find the missing integer. Can you do it
> in O(n) time?
>
>
>
> Thanks & Regards
> Shashank Mani
>
> --
> 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.
>
>


-- 
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

-- 
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] spoj problem - INFINITY

2011-03-03 Thread Vishnutej Mylavarapu
When I submit..Im getting a WA

On Thu, Mar 3, 2011 at 11:55 PM, D.N.Vishwakarma@IITR wrote:

> *this code is perfectly working . use gcc based compiler
> *
>
> On Thu, Mar 3, 2011 at 11:34 PM, Vishnutej  > wrote:
>
>> I dunno y dis code isnt working.
>>
>> #include
>> #include
>> using namespace std;
>> int main()
>> {
>> cout<::infinity();
>> }
>>
>>
>> Thnx in advance.
>>
>>
>> --
>> 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.
>>
>>
>
>
> --
> *Deoki Nandan Vishwakarma
> IITR MCA
> Mathematics Department
> *
>
>  --
> 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.
>



-- 

*-Vishnutej Mylavarapu.*

-- 
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: Amazon Question

2011-03-03 Thread Gunjan Sharma
And Integers too :P

On Fri, Mar 4, 2011 at 12:03 AM, nishaanth  wrote:

> @Gunjani made a mistake...u r right...but there is one more hidden
> assumption that the numbers are positive integers.
>
>
> On Thu, Mar 3, 2011 at 10:57 PM, sukhmeet singh wrote:
>
>> he already  pointed out that  there are no repetations..!!
>>
>>
>> On Thu, Mar 3, 2011 at 9:40 PM, Vipin Agrawal 
>> wrote:
>>
>>> take an example
>>>
>>> 3 3 3 5 5 5 7 8
>>>
>>> I think this would fail
>>>
>>> On Mar 3, 8:22 pm, Ankit Sinha  wrote:
>>> > It is funny but right input is as mentioned earlier to rahul. 0,2,3,8,
>>> > 10, 12, 14., 15 :).. Sorry for unnecessarily flooding your mail
>>> > accounts. Please ignore previous post
>>> >
>>> > thanks,
>>> > ankit!!
>>> >
>>> > On Thu, Mar 3, 2011 at 8:15 PM, rajul jain 
>>> wrote:
>>> > > i think he is wrong bcoz this array in not sorted one.
>>> > > so solution of Ankit is right.
>>> >
>>> > > On Thu, Mar 3, 2011 at 7:33 PM, nishaanth 
>>> wrote:
>>> >
>>> > >> Ignore the previous post..there is a small error in the code..
>>> > >> @Ankit..your algm is O(n)...you should split the problem size to n/2
>>> at
>>> > >> every stage...rather you are again computing both the subarrays..
>>> > >> Here is the correct code...
>>> > >> int BsearchElemEqualIndex (int *a, int start, int end)
>>> > >> {
>>> > >>int mid = (((end - start) >> 1) + start);
>>> > >>if (a[mid] == mid)
>>> > >>return a[mid];
>>> > >>else if (a[mid] != mid)
>>> > >>{
>>> > >>if (mid == start || mid == end)
>>> > >>{
>>> > >>return -1;
>>> > >>}
>>> > >>else
>>> > >>{
>>> > >>   if(a[mid] < mid )
>>> > >>BsearchElemEqualIndex (a, start, mid);
>>> > >>else
>>> > >>BsearchElemEqualIndex (a, mid + 1, end);
>>> > >>}
>>> > >>}
>>> > >> }
>>> >
>>> > >> int _tmain(int argc, _TCHAR* argv[])
>>> > >> {
>>> > >>int a[SIZE] = {5,9,3,8,1,2,6,7};
>>> > >>int x = BsearchElemEqualIndex (a, 0, SIZE);
>>> > >>printf ("%d", x);
>>> > >>system ("PAUSE");
>>> > >>return 0;
>>> > >> }
>>> > >> S.Nishaanth,
>>> > >> Computer Science and engineering,
>>> > >> IIT Madras.
>>> >
>>> > >> --
>>> > >> 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.
>>
>
>
>
> --
> S.Nishaanth,
> Computer Science and engineering,
> IIT Madras.
>
> --
> 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
Gunjan Sharma
Chairman IEEE Students Chapter IIT Roorkee
B.Tech IV year CSE

Contact No- +91 9997767077

-- 
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: Missing Number in New Way Please Read Question Carefully..

2011-03-03 Thread Jammy
for numbers from 0 to n, if you count the numbers whose LSB is 0 vs.
those has 1, if count(0) > count(1), the missing number's LSB is 1,
otherwise it's 0. Continue for the second LSB, your can find the
missing number bitwise.

On Mar 1, 3:14 pm, bittu  wrote:
> An array A[1...n] contains all the integers from 0 to n except for one
> number which is missing. In this problem, we cannot access an entire
> integer in A with a single operation.
> The elements of A are represented in binary, and the only operation we
> can use to access them is “fetch the jth bit of A[i]”, which takes
> constant time. Write code to find the missing integer. Can you do it
> in O(n) time?
>
> Thanks & Regards
> Shashank Mani

-- 
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: sort partially sorted linked list

2011-03-03 Thread Jammy
More comments on Ashish's approach. When implementing, you could
reverse the list when you see it's in descending order. Then merge
would be easier.

On Mar 3, 1:03 am, Ashish Goel  wrote:
> find two consecutive sequences(can be two increasing2I, 1i1d,1d1i,2D), merge
> them and then merge every next sequence with this merged sequence
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
>
>
>
>
>
> On Wed, Mar 2, 2011 at 8:33 PM, Shreyas VA  wrote:
> > I think in this case bubble sort with early exit will be efficient
>
> > On Wed, Mar 2, 2011 at 8:16 PM, snehal jain  wrote:
>
> >> The LL is in alternating ascending and descendin orders. Sort the list
> >> efficiently
> >> egs: 1->2->3->12->11->2->10->6->NULL
>
> >> --
> >> 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.



[algogeeks] Re: Maze & labyrinth Solve Puzzle & WAP Efficiently

2011-03-03 Thread Jammy
BFS search the maze

On Mar 2, 11:26 am, Don  wrote:
> class coord
> {
> public:
>   int x;
>   int y;
>
> };
>
> class SolveMaze
> {
> public:
>   SolveMaze() { location.x = location.y = 0; }
>   bool Explore();
> private:
>   list visited;
>   coord location;
>
> };
>
> bool Explore()
> {
>   // Determine if we've already been here
>   if (visited.found(location))
>     return false;
>
>   // Base case, we are at an exit
>   if (HasLadder()) return true;
>
>   // Remember that we have been here
>   visited.push(location);
>
>   // Try all four directions
>   for(direction = 0; direction < 4; ++direction)
>   {
>     if (TryMove(direction))
>     {
>       coord prev(location);  // Copy current location
>
>       // Track our current location
>       switch(direction)
>       {
>         case 0: --location.y; break;
>         case 1: ++location.x; break;
>         case 2: --location.x; break;
>         case 3: ++location.y; break;
>       }
>
>       // Explore from new location
>       if (this->Explore()) return true;
>
>       TryMove(3-direction);  // Assume 3-direction is opposite move of
> direction
>
>       // Back out location
>       location = prev;
>     }
>   }
>
>   // Remove current location from list
>   visited.pop();
>
>   // No exit found
>   return false;
>
> }
>
> On Mar 2, 9:05 am, bittu  wrote:
>
>
>
>
>
>
>
> > You are in a maze(like a labyrinth), and you open your eyes so you
> > don't know your position. The maze has walls and you can move only in
> > up, right, left and down directions. You can escape the maze when you
> > find a ladder.
>
> > The following API is given:
> > bool TryMove(direction) - returns true when you don't hit a wall;
> > bool HasLadder() - return true if you found the ladder.
>
> > Write a method bool Explore() that returns true if you can escape the
> > maze, false otherwise. Also, provide test cases.
>
> > A Good Explanation & Pseudo-code, Algorithmic discussion
> > needed..Object Oriented is Also Welcome
>
> > Thanks & Regards
> > Shahsank

-- 
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: Maze & labyrinth Solve Puzzle & WAP Efficiently

2011-03-03 Thread Don
The problem with BFS is that you have to remember how to get from
where you are to every other point you have explored.
Of course, the problem with a depth-first search is that in an
unbounded maze, you may never reach a point even if it is very close
to your starting point.

Don

On Mar 3, 1:31 pm, Jammy  wrote:
> BFS search the maze
>
> On Mar 2, 11:26 am, Don  wrote:
>
> > class coord
> > {
> > public:
> >   int x;
> >   int y;
>
> > };
>
> > class SolveMaze
> > {
> > public:
> >   SolveMaze() { location.x = location.y = 0; }
> >   bool Explore();
> > private:
> >   list visited;
> >   coord location;
>
> > };
>
> > bool Explore()
> > {
> >   // Determine if we've already been here
> >   if (visited.found(location))
> >     return false;
>
> >   // Base case, we are at an exit
> >   if (HasLadder()) return true;
>
> >   // Remember that we have been here
> >   visited.push(location);
>
> >   // Try all four directions
> >   for(direction = 0; direction < 4; ++direction)
> >   {
> >     if (TryMove(direction))
> >     {
> >       coord prev(location);  // Copy current location
>
> >       // Track our current location
> >       switch(direction)
> >       {
> >         case 0: --location.y; break;
> >         case 1: ++location.x; break;
> >         case 2: --location.x; break;
> >         case 3: ++location.y; break;
> >       }
>
> >       // Explore from new location
> >       if (this->Explore()) return true;
>
> >       TryMove(3-direction);  // Assume 3-direction is opposite move of
> > direction
>
> >       // Back out location
> >       location = prev;
> >     }
> >   }
>
> >   // Remove current location from list
> >   visited.pop();
>
> >   // No exit found
> >   return false;
>
> > }
>
> > On Mar 2, 9:05 am, bittu  wrote:
>
> > > You are in a maze(like a labyrinth), and you open your eyes so you
> > > don't know your position. The maze has walls and you can move only in
> > > up, right, left and down directions. You can escape the maze when you
> > > find a ladder.
>
> > > The following API is given:
> > > bool TryMove(direction) - returns true when you don't hit a wall;
> > > bool HasLadder() - return true if you found the ladder.
>
> > > Write a method bool Explore() that returns true if you can escape the
> > > maze, false otherwise. Also, provide test cases.
>
> > > A Good Explanation & Pseudo-code, Algorithmic discussion
> > > needed..Object Oriented is Also Welcome
>
> > > Thanks & Regards
> > > Shahsank
>
>

-- 
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: Who Loves Circus .....

2011-03-03 Thread Sachin Agarwal
1. sort the pairs with key as one of the parameters
2. find the longest increasing sub-sequence (not necessarily
contiguous) from the sorted list with key the the other parameter.

Sachin

On Mar 1, 3:02 pm, bittu  wrote:
> A circus is designing a tower routine consisting of people standing
> atop one another’s
> shoulders. For practical and aesthetic reasons, each person must be
> both shorter and lighter than the person below him or her. Given the
> heights and weights of each person in the circus, write a method to
> compute the largest possible number of people
> in such a tower.
>
> for example
> Input (ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68,
> 110)
> output..??
>
> Thanks & Regards
> Shashank

-- 
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] spoj problem - INFINITY

2011-03-03 Thread D.N.Vishwakarma@IITR
*which compiler you r using?
*
On Fri, Mar 4, 2011 at 12:15 AM, Vishnutej Mylavarapu <
mylavarapu.vishnu...@gmail.com> wrote:

> When I submit..Im getting a WA
>
> On Thu, Mar 3, 2011 at 11:55 PM, D.N.Vishwakarma@IITR 
> wrote:
>
>> *this code is perfectly working . use gcc based compiler
>> *
>>
>> On Thu, Mar 3, 2011 at 11:34 PM, Vishnutej <
>> mylavarapu.vishnu...@gmail.com> wrote:
>>
>>> I dunno y dis code isnt working.
>>>
>>> #include
>>> #include
>>> using namespace std;
>>> int main()
>>> {
>>> cout<::infinity();
>>> }
>>>
>>>
>>> Thnx in advance.
>>>
>>>
>>> --
>>> 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.
>>>
>>>
>>
>>
>> --
>> *Deoki Nandan Vishwakarma
>> IITR MCA
>> Mathematics Department
>> *
>>
>>  --
>> 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.
>>
>
>
>
> --
>
> *-Vishnutej Mylavarapu.*
>
>  --
> 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.
>



-- 
*Deoki Nandan Vishwakarma
IITR MCA
Mathematics Department
*

-- 
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: brain teaser

2011-03-03 Thread rajul jain
but they cannot communicate with each other (neither talking not hearing)
they just see person stand in front of him.

On Thu, Mar 3, 2011 at 11:04 PM, Dave  wrote:

> I have a way to save 19. Let each prisoner have his own private
> variable C, which he initializes to RED if he sees an odd number of
> red hats, or to BLACK if he sees an even number of red hats. The last
> man in the row announces his C. Every time someone announces the color
> RED, everyone ahead of him flips his C to the other color. In turn,
> each remaining man announces his C.
>
> Dave
>
> On Mar 3, 2:18 am, freecoder  wrote:
> > You are one of 20 prisoners on death row with the execution date set
> > for tomorrow.
> >
> > Your king is a ruthless man who likes to toy with his people's
> > miseries. He comes to your cell today and tells you:
> >
> > “I’m gonna give you prisoners a chance to go free tomorrow. You will
> > all stand in a row (queue) before the executioner and we will put a
> > hat on your head, either a red or a black one. Of course you will not
> > be able to see the color of your own hat; you will only be able to see
> > the prisoners in front of you with their hats on; you will not be
> > allowed to look back or communicate together in any way (talking,
> > touching.)
> >
> > (The prisoner in the back will be able to see the 19 prisoners in
> > front of him
> > The one in front of him will be able to see 18…)
> >
> > Starting with the last person in the row, the one who can see
> > everybody in front of him, he will be asked a simple question: WHAT IS
> > THE COLOR OF YOUR HAT?
> >
> > He will be only allowed to answer “BLACK” or “RED”. If he says
> > anything else you will ALL be executed immediately.
> >
> > If he guesses the right color of the hat on his head he is set free,
> > otherwise he is put to death. And we move on to the one in front of
> > him and ask him the same question and so on…
> >
> > Well, good luck tomorrow, HA HA HA HA HA HA!”
> >
> > Now since you all can communicate freely during the night, can you
> > find a way to guarantee the freedom of some prisoners tomorrow? How
> > many?
>
> --
> 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.