
Asked in Nagarro
Count Palindrome Words in a String
Given a string 'S' consisting of words, your task is to determine the number of palindrome words within 'S'. A word is considered a palindrome if it reads the same backward as it does forward.
Input:
The first line contains an integer 'T' representing the number of test cases. Each test case is given by a single line containing the string 'S'.
Output:
For each test case, output the number of palindrome words found in the string 'S', one per line.
Example:
Input:
2
Madam oyo cat
Was it a car or a cat I saw
Output:
2
3
Constraints:
- 1 <= T <= 10
- 0 <= |S| <= 10^5
- The string 'S' contains only whitespace, lowercase, and uppercase English letters.
Note:
Words are separated by one or more whitespace characters.

AnswerBot
4mo
Count the number of palindrome words in a given string.
Split the string into words using whitespace as delimiter.
Check each word if it is a palindrome by comparing it with its reverse.
Increment a coun...read more
Help your peers!
Add answer anonymously...
Top Technical Trainee Interview Questions Asked at Nagarro
Q. Counting Derangements Problem A derangement is a permutation of 'N' elements, wh...read more
Q. Detect and Remove Loop in Linked List For a given singly linked list, identify i...read more
Q. Character Formation Check Determine if the second string STR2 can be constructed...read more
Interview Questions Asked to Technical Trainee at Other Companies
Top Skill-Based Questions for Nagarro Technical Trainee
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

