Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 909 Bytes

File metadata and controls

35 lines (24 loc) · 909 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 Array, don't use the following built-in methods on Array:

  • push / << / unshift
  • 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