A Stack is an Array, but where you only add and remove the very last element.

All operations on a stack take O(1) time. This is because you never insert or delete an element in the middle of the array, so you never have to shift any elements over.

Here's an example:

Read/Write Time O(1)O(1)

Append/Pop Time O(1)O(1)

You'll get practice using Stacks in the next group of problems. Usually you don't have to do much thinking - Stacks just arise naturally when you solve the problem.

Mark as Completed:
Test your code to get an output here!