# lucky number

we have to input n numbers as per users choice like if n=4 we input the numbers 8,7,5,2 make the first number zero and move that many steps ahead like 8 is when made zero and we move 8 steps we move to 5(dont include 8 again)and we make 5 zero and then move 5 steps and come to 2 and then the number which has not been zero till last is the lucky number (here the answer is 7)

It’s a standard josephus problem which can easily be done with help of circular linked list. just create a link list with the numbers given and then join the end with start and remove the first and iterate to the list and get the next position until the list have only one element.

see this for better understanding. Hope this helps!

please provide a link to the question. It depends upon constraints. If they are small a simple brute force will work. But If they are large, then will have to think on a mathematical approach.

the question is given by school teacher and there is no link to the question

So u’re getting your homework done by us? XD hehee

Please explain your problem so that people can understand atleast what you are trying to say…I really dont get your question

the question is that we have to input n numbers (zero cant be input)in array .for example we input 4 numbers (n=4)the numbers are 8,7,5,2.we have to move 8 steps ahead whichever number is first move that many steps and make that number zero when we move 8 steps we come to 5 and make 5 equal to 0 and then move 5 steps in array then we come to 2 and then make 2 equal to zero and move 2 steps (we cant move 2 steps as all numbers are zero except one number that is 7 )so 7 is the lucky number.