Find First Palindromic String in the Array

Easy Topics Company Tags

Scan words from left to right and return the first word whose letters match when read in reverse order. If no word meets this condition, return the empty string "".

Example 1:

Input: words = ["desk","level","noon"]

Output: "level"

Explanation: The word level reads the same in both directions and appears before noon. Return level even though noon also qualifies.

Example 2:

Input: words = ["ab","cd"]

Output: ""

Explanation: Neither ab nor cd matches its reverse, so return an empty string.

Example 3:

Input: words = ["x","radar"]

Output: "x"

Explanation: A single letter always reads the same in both directions. The first word x therefore qualifies immediately.

Constraints:

  • 1 <= words.length <= 100
  • 1 <= words[i].length <= 100
  • Every word contains only lowercase English letters.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.