Find First Palindromic String in the Array

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.

30:00

Find First Palindromic String in the Array
easy
Free written solution
Topics
Companies

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.

Example 1:
Input: {"words":["abc","car","ada","racecar","cool"]}
Output: ada
Constraints:
  • 1≤words.length≤1001 \leq \text{words.length} \leq 100

  • 1≤words[i].length≤1001 \leq \text{words}[i].\text{length} \leq 100

  • words[i] consists only of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"words":["abc","car","ada","racecar","cool"]}

Check the words in order. The first one that reads the same from both ends is the answer.

words, checked left to right

abc
car
ada
racecar
cool

current word

Variables
VariableValue
word-
left-1
right-1
DepthFunction Call
Stack empty
0/9