Lecture
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"
Previous lessonStack: Data Entered Last Comes Out FirstNext lessonQueue: First In, First Out Data Structure
Lessons in this chapter · Introduction to Data Structures / Algorithms - Time Complexity, Space Complexity, Arrays, Stacks, Queues, Linked Lists, Hash Tables
- 1. The Core of Programming - Data Structures and Algorithms
- 2. What is Algorithm Complexity?
- 3. Time and Space Complexity of Algorithms
- 4. Storing Data Sequentially with Array
- 5. Coding Quiz - Implementing an Array
- 6. Stack: Data Entered Last Comes Out First
- 7. Coding Quiz - Implementing a Stack
- 8. Queue: First In, First Out Data Structure
- 9. Coding Quiz - Implementing a Queue
- 10. Creating a Linked List Structure Using Nodes
- 11. Coding Quiz - Implementing a Linked List
- 12. Storing Key-Value Pairs with Hash Table
- 13. Coding Quiz - Implementing a Hash Table
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help