> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Find First Palindromic String in the Array

> Tested Python solution for LeetCode 2108 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 2108, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [Two Pointers](/catalog/topics/two-pointers), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/find-first-palindromic-string-in-the-array/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 2108   # by problem number
lcpy gen -s find_first_palindromic_string_in_the_array   # by problem name
```

## Problem

Given an array of strings `words`, return the first **palindromic** string in the array. If there is no such string, return an **empty string** `""`.

A string is **palindromic** if it reads the same forward and backward.

### Examples

```
Input: words = ["abc","car","ada","racecar","cool"]
Output: "ada"
```

**Explanation:** The first string that is palindromic is "ada". Note that "racecar" is also palindromic, but it is not the first.

```
Input: words = ["notapalindrome","racecar"]
Output: "racecar"
```

**Explanation:** The first and only string that is palindromic is "racecar".

```
Input: words = ["def","ghi"]
Output: ""
```

**Explanation:** There are no palindromic strings, so the empty string is returned.

### Constraints

* `1 <= words.length <= 100`
* `1 <= words[i].length <= 100`
* `words[i]` consists only of lowercase English letters.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_first_palindromic_string_in_the_array/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_first_palindromic_string_in_the_array/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(total characters)
    # Space: O(1)
    def first_palindrome(self, words: list[str]) -> str:
        for word in words:
            if word == word[::-1]:
                return word
        return ""
```

## Complexity

| Time | Space |
| - | - |
| O(total characters) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.