This Mismatch… ❖ Is keeping programmers from getting jobs ❖ Is likely due to a lack of interview training (especially compared to the other training we do in our industry) ❖ Is fixable
What Do I Know About This? ❖ I work for NoRedInk ❖ We get a lot of applicants ❖ Roughly 75% of the candidates fail our “take home” ❖ Around 30% of the rest fail their first technical interview ❖ I see a lot of what doesn’t work
Study ❖ Interviews commonly focus on a certain subset of programming knowledge ❖ This probably isn’t knowledge that you use daily ❖ Ensuring it’s fresh in your brain can help
Big O Notation ❖ A metric used to describe an upper bound on algorithm efficiency ❖ Can be used for time or space ❖ Drops constants and non-dominant terms ❖ Adds independent work; multiplies dependent work ❖ Not just an academic curiosity! It can help you solve problems faster and easier!
A: 13, 27, 35, 40, 49, 55, 59 B: 17, 35, 39, 40, 55, 58, 60 Given two sorted arrays, find the elements in common. The arrays are the same length and each has all distinct elements.
Bungling Towards Ideal a = [13, 27, 35, 40, 49, 55, 59] b = [17, 35, 39, 40, 55, 58, 60] i = 0 shared = b.each_with_object([ ]) do |n, array| while i < a.size && a[i] < n i += 1 end array << n if a[i] == n end p shared
Bungling Towards Ideal a = [13, 27, 35, 40, 49, 55, 59] b = [17, 35, 39, 40, 55, 58, 60] i = 0 shared = b.each_with_object([ ]) do |n, array| while i < a.size && a[i] < n i += 1 end array << n if a[i] == n end p shared
Bungling Towards Ideal a = [13, 27, 35, 40, 49, 55, 59] b = [17, 35, 39, 40, 55, 58, 60] i = 0 shared = b.each_with_object([ ]) do |n, array| while i < a.size && a[i] < n i += 1 end array << n if a[i] == n end p shared
Analyzing Algorithms module Fib module_function def recursive(i) return i if i < 2 recursive(i - 2) + recursive(i - 1) end def memoized(i) cache = Hash.new { |hash, n| hash[n] = n < 2 ? n : hash[n - 2] + hash[n - 1] } cache[i] end def dynamic(i) return i if i < 2 a, b = 0, 1 (i - 2).times do a, b = b, a + b end a + b end end
Analyzing Algorithms module Fib module_function def recursive(i) return i if i < 2 recursive(i - 2) + recursive(i - 1) end def memoized(i) cache = Hash.new { |hash, n| hash[n] = n < 2 ? n : hash[n - 2] + hash[n - 1] } cache[i] end def dynamic(i) return i if i < 2 a, b = 0, 1 (i - 2).times do a, b = b, a + b end a + b end end
Analyzing Algorithms module Fib module_function def recursive(i) return i if i < 2 recursive(i - 2) + recursive(i - 1) end def memoized(i) cache = Hash.new { |hash, n| hash[n] = n < 2 ? n : hash[n - 2] + hash[n - 1] } cache[i] end def dynamic(i) return i if i < 2 a, b = 0, 1 (i - 2).times do a, b = b, a + b end a + b end end
Analyzing Algorithms module Fib module_function def recursive(i) return i if i < 2 recursive(i - 2) + recursive(i - 1) end def memoized(i) cache = Hash.new { |hash, n| hash[n] = n < 2 ? n : hash[n - 2] + hash[n - 1] } cache[i] end def dynamic(i) return i if i < 2 a, b = 0, 1 (i - 2).times do a, b = b, a + b end a + b end end
Almost Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibRecursiveBench < Minitest::Benchmark def self.bench_range [1, 3, 30] end def bench_recursive_fib assert_performance_exponential do |n| Fib.recursive(n) end end end
Almost Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibRecursiveBench < Minitest::Benchmark def self.bench_range [1, 3, 30] end def bench_recursive_fib assert_performance_exponential do |n| Fib.recursive(n) end end end
Almost Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibRecursiveBench < Minitest::Benchmark def self.bench_range [1, 3, 30] end def bench_recursive_fib assert_performance_exponential do |n| Fib.recursive(n) end end end
More Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibMemoizedBench < Minitest::Benchmark def self.bench_range bench_exp(1, 1_000) end def bench_memoized_fib assert_performance_linear do |n| Fib.memoized(n) end end end
More Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibMemoizedBench < Minitest::Benchmark def self.bench_range bench_exp(1, 1_000) end def bench_memoized_fib assert_performance_linear do |n| Fib.memoized(n) end end end
More Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibMemoizedBench < Minitest::Benchmark def self.bench_range bench_exp(1, 1_000) end def bench_memoized_fib assert_performance_linear do |n| Fib.memoized(n) end end end
The Most Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibDynamicBench < Minitest::Benchmark def bench_dynamic_fib assert_performance_linear do |n| Fib.dynamic(n) end end end
The Most Helpful require "minitest/autorun" require "minitest/benchmark" require_relative "fib" class FibDynamicBench < Minitest::Benchmark def bench_dynamic_fib assert_performance_linear do |n| Fib.dynamic(n) end end end
The classic “Nine Balls” interview brainteaser You have nine balls. Eight are the same weight and one is heavier. You are given a balance which tells you only wether the left side or right side is heavier. Find the heavy ball in just two uses of the scale.
Practice ❖ Work code challenges ❖ http://exercism.io/ ❖ http://rubyquiz.com/ ❖ You need to be able to consistently solve Exercism size problems in one hour
Have Some Open Source ❖ Be able to point to a published gem ❖ It barely matters what it does ❖ The most important details are a strong README, clean code, tests, and documentation ❖ A small gem is fine
Maximizing for Success ❖ You probably won’t nail all of my tips every time ❖ That’s fine ❖ Interviews are hard for everyone and everyone makes mistakes ❖ Hit as many of the points we’ve discussed as you can ❖ Those you get will help