TCS Coding Practice Question | Palindrome String Last Updated : 11 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a string, the task is to check if this String is Palindrome or not using Command Line Arguments. Examples: Input: str = "Geeks" Output: No Input: str = "GFG" Output: Yes Approach: Since the string is entered as Command line Argument, there is no need for a dedicated input line Extract the input string from the command line argument Traverse through this String character by character using loop, till half the length of the sting Check if the characters from one end match with the characters from the other end If any character do not matches, the String is not Palindrome If all character matches, the String is a Palindrome Program: C // C program to check if a string is Palindrome // using command line arguments #include <stdio.h> #include <stdlib.h> #include <string.h> // Function to reverse a string int isPalindrome(char* str) { int n = strlen(str); int i; // Check if the characters from one end // match with the characters // from the other end for (i = 0; i < n / 2; i++) if (str[i] != str[n - i - 1]) // Since characters do not match // return 0 which resembles false return 0; // Since all characters match // return 1 which resembles true return 1; } // Driver code int main(int argc, char* argv[]) { int res = 0; // Check if the length of args array is 1 if (argc == 1) printf("No command line arguments found.\n"); else { // Get the command line argument // and check if it is Palindrome res = isPalindrome(argv[1]); // Check if res is 0 or 1 if (res == 0) // Print No printf("No\n"); else // Print Yes printf("Yes\n"); } return 0; } Java // Java program to check if a string is Palindrome // using command line arguments class GFG { // Function to reverse a string public static int isPalindrome(String str) { int n = str.length(); // Check if the characters from one end // match with the characters // from the other end for (int i = 0; i < n / 2; i++) if (str.charAt(i) != str.charAt(n - i - 1)) // Since characters do not match // return 0 which resembles false return 0; // Since all characters match // return 1 which resembles true return 1; } // Driver code public static void main(String[] args) { // Check if length of args array is // greater than 0 if (args.length > 0) { // Get the command line argument // and check if it is Palindrome int res = isPalindrome(args[0]); // Check if res is 0 or 1 if (res == 0) // Print No System.out.println("No\n"); else // Print Yes System.out.println("Yes\n"); } else System.out.println("No command line " + "arguments found."); } } Output: In C: In Java: Comment More infoAdvertise with us Next Article Find if string is K-Palindrome or not | Set 2 R RishabhPrabhu Follow Improve Article Tags : Interview Experiences TCS TCS-coding-questions Practice Tags : TCS Similar Reads Check if a palindromic string can be obtained by concatenating substrings split from same indices of two given strings Given two strings A and B of length N, the task is to check if any of the two strings formed by splitting both the strings at any index i (0 ⤠i ⤠N - 1) and concatenating A[0, i] and B[i, N - 1] or A[i, N - 1] and B[0, i] respectively, form a palindromic string or not. If found to be true, print "Y 15+ min read Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated Given two strings A and B of equal lengths, the task is to find an index i such that A[0...i] and B[i+1...n-1] give a palindrome when concatenated together. If it is not possible to find such an index then print -1. Examples: Input: S1 = "abcdf", S2 = "sfgba" Output: 1 S1[0..1] = "ab", S2[2..n-1] = 12 min read C Program to Check for Palindrome String A string is said to be palindrome if the reverse of the string is the same as the string. In this article, we will learn how to check whether the given string is palindrome or not using C program.The simplest method to check for palindrome string is to reverse the given string and store it in a temp 4 min read Palindrome String Coding Problems A string is called a palindrome if the reverse of the string is the same as the original one.Example: âmadamâ, âracecarâ, â12321â.Palindrome StringProperties of a Palindrome String:A palindrome string has some properties which are mentioned below:A palindrome string has a symmetric structure which m 2 min read Find if string is K-Palindrome or not | Set 2 Given a string, find out if the string is K-Palindrome or not. A K-palindrome string transforms into a palindrome on removing at most k characters from it.Examples: Input : String - abcdecba, k = 1 Output : Yes String can become palindrome by removing 1 character i.e. either d or e Input : String - 8 min read Number of Counterclockwise shifts to make a string palindrome Given a string of lowercase English alphabets, find the number of counterclockwise shifts of characters required to make the string palindrome. It is given that shifting the string will always result in the palindrome. Examples: Input: str = "baabbccb" Output: 2 Shifting the string counterclockwise 15+ min read Like