Count Palindrome Words in A String
You are given a string S of words. Your task is to find the number of palindrome words in the given string S. A word is called palindrome, if it reads the same backwards as forwards.
Note:
Words are separated by one or more whitespace characters.
For Example:
For the given string “Madam oyo cat”, “Madam”, and “oyo” are the palindrome words
Input format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first and only line of each test case contains the string S.
Output format:
For each test case, print the number of palindrome words in the given string S in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
0 <= |S| <= 10^5
All the characters of the string S contain whitespace, lowercase, and uppercase English letters only.
Time limit: 1 second
CodingNinjas
author
2y
1. We will take each word after a space “ “ in a sentence and pass it to a function.
2.The function transforms the characters of words in lowercase.
3. Now start traversing from the first character of t...read more
CodingNinjas
author
2y
Brute force
Steps:
- We initially initialize an empty string say temp and an ans variable to 0. Then, we will traverse the input string S from left to right and keep on adding the current character to th...read more
Help your peers!
Add answer anonymously...
Top Nagarro Technical Trainee interview questions & answers
Popular interview questions of Technical Trainee
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app