Please format the code so that it is readable and add some more necessary comments to make your approach clear.
I think it is clear enough,and I dont know how to format my code,sorry.
Is there somebody to help me?please tell me where is my wrong
Why are you making base comparisons to log N ? I think n/2 is the way to go if you want to start from the other end.
@thezodiac1994
It would not be n/2 as complexity becomes O((n/2)*n)=O(n^2), so here sorting becomes a better option …
but yeah there is a bug… it should be:
case1: k<logn
case2: k>n-logn
case3: use sorting
thanks
You didnt mention sorting as a case 3 and hence I was referring to the log N term.