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
11d

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...
Nagarro Technical Trainee Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter