Hi,

just compare the 0th position of the string with length-1 position of the
string, 2nd position of the string with length-2 postion of the string and
so.on

eg: 12132, in first comparison itself, will fail.

Thanks
Prasanna M

On Mon, Oct 13, 2014 at 4:47 AM, Carl Barton <odysseus.ulys...@gmail.com>
wrote:

> 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 <rishav.mish...@gmail.com> 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 algogeeks+unsubscr...@googlegroups.com.
>>
>
>  --
> 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 algogeeks+unsubscr...@googlegroups.com.
>



-- 
Thanks
Prasanna M

-- 
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 algogeeks+unsubscr...@googlegroups.com.

Reply via email to