Elements of Programming Interviews

  • Greedy algorithms
    • mostly used for optimizing (minimize, maximize) a set of choices
    • examples
      • counting change
      • optimizing intervals
    • often involves sorting first
    • doesn’t always lead to optimal solution, but can provide insight

Go

Useful packages: bufio, sort, os, strconv, strings

There are two ways to sort user defined types. One way is to satisfy sort.Interface by defining Len, Swap, and Less methods. The other is to call sort.Slice with a closure that satisfies the Less method:

sort.Slice(shifts, func(i, j int) bool {
  return shifts[i].finish < shifts[j].finish
})