572. Check if Stack is Palindrome

EasyStackStackString

Given a stack represented as an array, determine whether its contents read the same from bottom to top as from top to bottom. Return true or false. The input is JSON {stack}.

Input: JSON {stack}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"stack":[1,2,3,2,1]}
Output: true
Explanation: Reads the same both ways.
Example 2
Input: {"stack":[1,2,3]}
Output: false
Explanation: Not a palindrome.
Example 3
Input: {"stack":[7]}
Output: true
Explanation: A single element is a palindrome.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →