Ten interview problems: fast answer beside the brute-force answer ================================================================= 1. search insert position [1, 3, 5, 6] key=5 fast=2 brute-force=2 1. search insert position [1, 3, 5, 6] key=2 fast=1 brute-force=1 1. search insert position [1, 3, 5, 6] key=7 fast=4 brute-force=4 1. search insert position [1, 3, 5, 6] key=0 fast=0 brute-force=0 2. first and last position [5, 7, 7, 8, 8, 10] key=8 fast=[3, 4] brute-force=[3, 4] 2. first and last position [5, 7, 7, 8, 8, 10] key=6 fast=[-1, -1] brute-force=[-1, -1] 3. count occurrences [1, 2, 2, 2, 2, 2, 3] key=2 fast=5 brute-force=5 4. search in rotated array [4, 5, 6, 7, 0, 1, 2] key=0 fast=4 brute-force=4 4. search in rotated array [4, 5, 6, 7, 0, 1, 2] key=3 fast=-1 brute-force=-1 5. minimum of rotated array [3, 4, 5, 1, 2] (index of min) fast=3 brute-force=3 6. find a peak element [1, 2, 1, 3, 5, 6, 4] (any peak is valid) fast=5 brute-force=peaks at 1 and 5, 5 is a peak: true 7. integer square root x=4 fast=2 brute-force=2 7. integer square root x=8 fast=2 brute-force=2 8. koko eating bananas [3, 6, 7, 11] h=8 fast=4 brute-force=4 9. ship packages within D days weights 1..10 days=5 fast=15 brute-force=15 10. search a 2D matrix 3x4 matrix target=3 fast=true brute-force=true 10. search a 2D matrix 3x4 matrix target=13 fast=false brute-force=false