in c++ what will be the fastest logic to find next palindrome of a given 15 digit number? for example what will be the next palindrome of: 134567329807541 ?
Split the number into three parts, head
, mid
, tail
1345673 2 9807541
Reverse head
and compare it to tail
3765431
If reverse(head) <= tail
( if they are equal the initial input is a palindrome, and you want the next )
mid < 9
, increment midhead
part and set mid := 0
result := head mid reverse(head)
.
1345673 3 reverse(1345673) => 134567333765431
I believe it's like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With