You don't need to reverse anything. You reverse half the number and then
compare positions, why not just compare things straight away? Also note
that your solution is not n/2. Should the length be n it would be at least
n operations. n/2 to reverse half the string and then n/2 comparisons.
However, your method is depedent on the number of digits in a number and a
number n does not have n digits in it, it will be approximately log n. See
here for more information
http://math.stackexchange.com/questions/231742/proof-how-many-digits-does-a-number-have-lfloor-log-10-n-rfloor-1


On 12 October 2014 21:06, Rishav Mishra <[email protected]> wrote:

> Hi everyone,
>
> I was recently asked a question to find the most optimal solution to
> finding if a given number 'n' is a palindrome or not.
>
> I suggested reversing the first half of the number and comparing it with
> the second half, giving complexity O (n/2).
>
> He still seemed unsatisfied and wanted me to further optimize it. Any
> clues on how to optimize this simple question further!?
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].

Reply via email to