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.
- 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
- 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
- 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.
- easyBest day to buy and sell15 min
- mediumLargest sum of a run25 min
- mediumJump game25 min
- mediumGas station loop25 min
- mediumJump game II25 min
- mediumCut a string by its letters25 min
- easyThe value without a twin15 min
- easyCount the 1 bits from 0 to n15 min
- easyThe missing number15 min
- easyCount the 1 bits15 min
- easyReverse the 32 bits15 min
- mediumLargest product of a run25 min