A linear data structure that holds a linear, ordered sequence of elements. They can be implemented using arrays or linked lists.
<aside> 💡 Visualize a stack as a bunch of books stacked on top of each other, where you can only view and remove the top book. To access the bottom book, you need to remove all books one by one. This follows the Last In, First Out (LIFO) principle.
</aside>
push(item)
: Add an item to the top of the stack.
pop()
: Remove the item at the top and return its value.
peek()
: Return the value at the top without removing it.
isEmpty()
: Return true if the stack is empty.
Note - Time complexity of every operation is O(1).