July 04, 2022 |180 Views

    Sum of first K even-length Palindrome numbers

      Share   Like
    Description
    Discussion

    Given a integer k, find the sum of first k even-length palindrome numbers. 
    Even length here refers to the number of digits of a number is even.

     

    A naive approach will be to check every even length number, if it is a palindrome number then we sum it up. We repeat the same process for first K even length palindrome numbers and sum them up to get the sum.

     

    In this case complexity will go high as even length numbers are from 10-99 and then 1000-9999 and then so on… 
    10-99, 1000-9999, 100000-999999.. has 9, 90, 900 respectively palindrome numbers in them, so to check k numbers we have to check a lot of numbers which will not be efficient enough.
    Examples: 
     

    Input : k = 3
    Output : 66
    Explanation: 11 + 22 + 33  = 66 (Sum 
    of first three even-length palindrome 
    numbers)

    Sum of first K even-length Palindrome numbers : https://www.geeksforgeeks.org/sum-first-k-even-length-palindrome-numbers/