iq.lab
Python starts when a code cell comes near or you run one

Module 13 · 2 lessons · about 3 hours 50 minutes

Greedy and a little math

Greedy choices and how to tell when they are safe, Kadane's maximum subarray, and the few bit and number tricks interviews still use.

Lessons
0/2
Exercises
0/15
Code
0/2
Problems
0/12
Checkpoint
Not taken

Already comfortable with this? Take the checkpoint cold. If you pass, move on and come back only for what you missed.

  1. 1Greedy choicesA greedy algorithm takes the best-looking choice at each step and never takes it back. It is fast, and it is right only when you can argue that no better answer was thrown away.2 h 5 min
  2. 2Bits and small mathEvery integer is a row of bits, and a few operators work on all its bits at once: XOR cancels pairs, and `x & (x - 1)` removes the lowest 1. A little arithmetic does the rest: a sum formula finds a missing number, `%` keeps big numbers small, and Euclid's rule finds a gcd.1 h 45 min
  3. Checkpoint12 questions. Pass with 80% to finish the module.

Problems for this module

The lessons teach some of these step by step (each says which). The rest are practice: try each in its target time, and solved problems come back for spaced re-solves.

Next moduleInterview mode