565. Reverse a String Using Stack

EasyStackStackString

Given a string s, return the string reversed. (Conceptually, push every character onto a stack and pop them to build the reversed string.) The input is JSON {s}.

Input: JSON {s}.

Output: String — the reversed string.

Examples

Example 1
Input: {"s":"hello"}
Output: olleh
Explanation: Characters popped in reverse order.
Example 2
Input: {"s":""}
Output: 
Explanation: Empty stays empty.
Example 3
Input: {"s":"ab"}
Output: ba
Explanation: Two characters swapped.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →