Skip to main content
Back to problems
Leetcode
Easy
Arrays
Strings
Find First Palindromic String In The Array

Return the first string in the array that reads the same forward and backward.

Acceptance 0%
Problem Statement

Problem

Given an array of strings, scan it from left to right and find the first string that is a palindrome.

A string is a palindrome if it is identical when read from left to right and from right to left. If no string in the array is a palindrome, return an empty string.

Notes

  • You must return the earliest palindromic string by index, not the longest one.
  • Comparisons are case-sensitive.
  • An empty string is considered a palindrome.

Input Format

  • A list of strings words.

Output Format

  • Return the first palindromic string in words.
  • If none exists, return "".

Constraints

  • 1 <= words.length
  • Each words[i] is a string.
  • Treat palindromes using exact character matching.
Examples
Sample cases returned by the problem API.

Example 1

Input

words = ["abc","car","ada","racecar","cool"]

Output

"ada"

Explanation

"abc" and "car" are not palindromes. "ada" is the first string that reads the same forward and backward.

Example 2

Input

words = ["not","a","palindrome"]

Output

"a"

Explanation

A single-character string is always a palindrome, so the first palindrome is "a".

Show 1 more example

Example 3

Input

words = ["def","ghi"]

Output

""

Explanation

No string in the array is a palindrome.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.