Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 985 Bytes

basic_stack.markdown

File metadata and controls

39 lines (27 loc) · 985 Bytes

Basic Stack

A stack is a LIFO (last-in, first-out) data structure. The core operations are push which adds an element to the stack and pop with removes the top element of the stack.

Challenge

Implement a Stack which can...

  • push an element onto the stack
  • pop remove the top element from the stack and return the element
  • count the number of elements on the stack
  • peek at the top element without removing it
  • max find the largest value in the stack

You can assume that this stack only holds integers.

Limitations

While you can use a Ruby or JavaScript Array, don't use the following built-in methods on Array:

  • push / unshift (or shovel operator in Ruby)
  • pop / shift
  • max / max_by / min / min_by
  • count / length
  • first / last

And, for an added challenge, can you do it without using negative array indexes?

Solutions

Video walk-through

https://vimeo.com/125297304