Waddle Street
Programs
  • All programs
  • Insight programs
  • What changed
  • Competitions
Networking
  • Contacts
  • Find people
  • Write a note
Prep
  • Learn
  • Drills
  • My answers
  • Markets
  • Resume review
  • Resources
Industries
  • Overview
  • Find your fit
  • Guides
Waddle Street
LearnDrillsMy answersMarketsResume reviewResources

Learn

Learn/Coding and algorithms
LearnCoding and algorithms

0 of 6 lessons, sign in to save

B Basic

  • Complexity and what n allows9m
  • Arrays, hashing, and two pointersPro11m
  • Sorting, selection, and binary searchPro10m

A Advanced

  • Heaps, stacks, and streaming dataPro12m
  • Dynamic programming, with a probability flavorPro12m
  • Simulation done rightPro11m
  • FlashcardsPro0/16
  • Basic quizPro80% passes
  • Advanced quizPro80% passes
  • Terms

Basic, lesson 1 of 3

Complexity and what n allows

Before writing a line, read the input size. It tells you which complexity will pass, which tells you which algorithm to look for.

9 min, 3 checks

1Counting work

Big O counts how work grows with the input, ignoring constants. A loop over n items is O(n). A loop inside a loop over pairs is O(n^2): for n = 100 the pairs with i < j number 100 x 99 / 2 = 4,950. Halving a search range each step is O(log n).

nFits in about a secondTypical tools
Up to 20O(2^n), O(n!) for tiny nBrute force, bitmasks
Up to 5,000O(n^2)Pairs, simple dynamic programming
Up to 1,000,000O(n log n)Sorting, heaps, binary search
Up to 100,000,000O(n)One pass, hashing, prefix sums
A rough budget: about 100 million simple operations a second in a compiled language, far fewer in plain Python

Check 1

A double loop compares every pair (i, j) with i < j in a list of 100 items. How many comparisons?

Check 2

Binary search on a sorted list of 1,000,000 items. At most how many halvings does it take to find an item?

2Space and hidden costs

Memory counts too: a hash map of n items is O(n) extra space, and an interviewer who asks for O(1) space wants you to reuse the input or keep a few variables. Watch for hidden loops: in Python, slicing a list, "x in list", and building a string with += inside a loop are each O(n) per call.

Check 3

n is 1,000,000 and you have one second in C++. Which complexity is safe?

How this gets asked in an interview

Say the brute force and its complexity first, then name what the input size requires. Interviewers grade the path from slow to fast as much as the final code.

  • What is the complexity of your solution, in time and in memory?
  • n is up to ten million. Does your approach still work?
  • Can you do it without the extra hash map?
Drill Coding, ten questions

3 checks in this lesson. Sign in to keep your progress.

Next lesson