I use this for reversing a string, but it has O(n) :


How can I reverse a string in O(n/2) ?

  • 2
    \$\begingroup\$ Welcome to Code Review. Please see How do I ask a good question? While not necessarily off-topic, your question's scope is so limited (1 single expression) that there is only very little we can actually review. \$\endgroup\$
    – Phrancis
    Apr 6, 2016 at 20:21
  • \$\begingroup\$ Being too short has never been a reason to close. If you think there's no useful advice you can note that, but the question is not off topic. \$\endgroup\$ Apr 7, 2016 at 8:42
  • 3
    \$\begingroup\$ I'm voting to close this question as off-topic because you're not looking for a code review and just an alternative solution on a black-box level ("gimme the better codes"). \$\endgroup\$
    – Pimgd
    Apr 7, 2016 at 9:11
  • \$\begingroup\$ @Pimgd I'm not convinced that it is off-topic. The question is basically asking "How can I do it faster?" The answer is, essentially, "Your code is fine." \$\endgroup\$ Apr 8, 2016 at 14:25
  • \$\begingroup\$ @200_success OP would not be helped by a review talking about that poor variable naming, what is y supposed to mean? They're looking for an alternative code snippet that will replace this one. \$\endgroup\$
    – Pimgd
    Apr 8, 2016 at 14:34

1 Answer 1


You did it already: \$O(\frac{n}{2})\$ is exactly the same as \$O(n)\$.


Not the answer you're looking for? Browse other questions tagged or ask your own question.