• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

Palindromic String

  • January 6, 2020
  • CODE OF GEEKS
  • 2

You are provided with a string of numbers, check whether it is a palindrome or not. If it is not a palindrome, then, reverse the string, add it to the original string and check again. You are required to repeat the process until it becomes palindrome. Find the length of palindromic string. 

Input : 

First Input : String

Output : Length of Palindrome

Sample Testcases :

I/P 1:

1

O/P 1:

1

I/P 2:

145

O/P 2:

3




Explanation : 


Given string is 145, it is not a palindrome. Reversing and adding, 145+541 = 686, Hence it is a palindrome.


Solution :

def palincheck(num):
    s=str(num[::-1])
    if s==num:
        return True
    return False
n=(input())
val=0
k=0
while(True):
    if(palincheck(n)):
        val=len(n)
        print(val)
        break
    else:
        s1 = str(n[::-1])
        k=int(n)+int(s1)
        n=str(k)
        palincheck(n)


Tags: infosys last year handson problemsinfytqinfytq examinfytq examinationinfytq handson problems last yearinfytq handson problems of last yearinfytq handson questionsinfytq last year problemsinfytq last year questionsLast year questions Infytqpractice infyprepare infytq question
  • Previous INFOSYS INTERVIEW EXPERIENCE 2019 – POWER PROGRAMMER – 15
  • Next Arithmetic Expression

2 comments on “Palindromic String”

  1. anonymous says:
    March 10, 2020 at 4:54 pm

    It Can Be Done Like This:

    S=Input()
    While(S!=S[::-1]):
    S=Str(Int(S)+Int(S[::-1]))
    Print(len(S))

    Reply
  2. ANONYMOUS says:
    June 13, 2020 at 1:42 pm

    import java.io.BufferedReader;
    import java.io.InputStreamReader;

    public class PalindromeString {
    public static void main(String[] args) throws Exception{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    String s=br.readLine();
    long n=Long.parseLong(s);
    while(!isPalin(s)){
    s=””+(n+Long.parseLong(reverse(n)));
    System.out.println(s);
    }
    System.out.println(s.length());
    }
    public static String reverse(long n){
    String s=””+n;
    String input =s;

    StringBuilder input1 = new StringBuilder();
    input1.append(input);
    input1 = input1.reverse();

    return input1.toString();
    }
    public static boolean isPalin(String s){
    int i=0,j=s.length()-1;
    while(i<=j){
    if(s.charAt(i)==s.charAt(j)){
    i++;j–;
    }
    else{
    return false;
    }
    }
    return true;
    }

    }

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

What is Amazon Web Services | AWS Regions & AZs | Different AWS Services
  • October 19, 2021
TCS Reasoning 2021
  • October 4, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →