http://code.geeksforgeeks.org/V7ZSoq

what i did was to simply find the number before query …and then do as below-

Suppose the numbers are {11, 12, 13, 14, 15, 16} , and suppose 16 is the query, then find out 15 by binary search (the no less than k).

Then i will have a total of 4 numbers left to eat up(11 12 13 14) so 15 eats one to get to 16 … So now left with 3 … 14 eats 2 so we are left with (3-2-1)…including 14 also gone thereby total number being 16,15,14 …

(EDIT- From Vijju123- Basically what hes trying to say is that snake no. 15 will eat one snake and be of length 16, and 14 will eat 2 snakes and become of length 16.)

it works for repetitive elements also…then where am I going wrong can anyone help please…?