Coding Quiz
In this coding quiz, you will implement a solution function that uses a stack to reverse a given string.
To accomplish this, insert each character of the string into the stack, then pop the characters from the stack one by one to form a new reversed string.
Function Signature
def solution(s):
# Write your code here
return
Constraints
-
The input string consists only of English letters.
-
Use stack operations
push(add) andpop(remove) to solve the problem. -
You can use a list to implement the stack.
Example
-
Input:
solution("hello") -
Output:
"olleh"
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.