As we start every time from the beginning, so 1 will never be deleted
hence in last it will remain there

I faced the same Question in MS Written where question was..Given a
number find if the number is Lucky or not?

that can be easily found because every time we remove the numbers at
even indexes(assuming indexes start at 1) now if at any time if index
goes even number is not lucky and if it is odd after the operation new
index will be (i+1)/2
Overall Complexity O(lgn)

On Wed, Jul 27, 2011 at 9:46 AM, bharath <bharath.sri...@gmail.com> wrote:
> This is the extended Josephus problem. More details and solution
> formulation here:
> http://www.cs.man.ac.uk/~shamsbaa/Josephus.pdf
>
>
> On Jul 26, 11:04 pm, Nikhil Gupta <nikhilgupta2...@gmail.com> wrote:
>> Please suggest a good algo for this :
>>
>> You have numbers 1 to n (consider them arranged in a circular order)
>> Then starting from the first number, all alternate numbers are deleted. Once
>> the entire range is traversed with this procedure, the same is performed
>> from the beginning again (as they are circularly arranged).
>> This action is done until only one number is left. So given a range of
>> numbers, you have to use an algo to tell which number will be left in the
>> end.
>>
>> Example :
>>
>> 1 2 3 4 5 6 7 8 9 10 11 12 .......
>> 1 3 5 7 9 11 13 15 17 19 .....
>> 1 5 9 13 17 21 25 .....
>>
>> and so on.
>>
>> --
>> Nikhil Gupta
>> Senior Co-ordinator, Publicity
>> CSI, NSIT Students' Branch
>> NSIT, New Delhi, India
>
> --
> 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.

Reply via email to