First note that the person standing at the last position can be easily
found,because if it has to move by  X,then after shifting its position will
be N-X,which will be the position in the sorted array ,(Array becomes
sorted after shifting of the last person),and the number at position N-X
will be N-X.So the person at the last position is N-X.Try to perform the
same after deleting this element from the array.This will reduce the
problem to a query/update problem ,and you will need a data structure such
as balanced BST (such as AVL),or segment tree or BIT,or even tree
representation of lists.

-- 
*Regards,*
*Piyush Kapoor,*
*2nd year,CSE
IT-BHU*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to