Big-O & Your Two Workhorses

Two structures do most of the work

Ninety percent of everyday backend code β€” and most interview problems β€” leans on exactly two structures: the dynamic array (Ruby's Array) and the hash map (Ruby's Hash).

Before the structures, one piece of vocabulary: Big-O. It describes how the work grows as the input n grows. O(1) means constant β€” the same cost whether you have 10 items or 10 million. O(n) means linear β€” twice the data, twice the work.

The whole game is spotting when an O(n) scan can become an O(1) lookup.