Skip to content

Instantly share code, notes, and snippets.

@manchunlam
Forked from dyoung522/tech-questions.md
Created June 23, 2016 19:57
Show Gist options
  • Save manchunlam/f2b5f1910e740badea997627726b931d to your computer and use it in GitHub Desktop.
Save manchunlam/f2b5f1910e740badea997627726b931d to your computer and use it in GitHub Desktop.
Technical Interview Questions

Technical Interview Questions

General

  • In as much detail as you like, explain what happens when I type "google.com" into my browser's address bar and press enter.
  • Explain the difference between dynamic vs. static programming languages? What are the advantages/disadvantages of each?
  • What's something you love/hate about your favorite programming language?
  • What tools do you use for your day to day work? Language, IDEs/editors, version control, build systems, provisioning, etc.?
  • What's the difference between an class vs. an object?
  • What is inheritance? What are some alternate ways to reuse logic without using it? What are some downsides to it?
  • What is polymorphism? Why is it useful?
  • Describe the differences between unit and integration testing. When do you favor one or the other?

Design

  • Describe MVC pattern

  • Describe any design patterns you're familiar with. Discuss the tradeoffs.

  • Explain what "refactoring" means to you?

    • How do you go about refactoring?
    • What are common refactorings you reach for?
    • What signals (smells) do you look for to evaluate whether something needs to be refactored?
    • Are there times when you should/should not refactor something?
  • Let's say we have a "customer charging service" that needs to interact with our credit card gateway. The gateway has a testing playground, however, it's sometimes offline causing the current tests to break frequently, or timeout and fail when under heavy load. How would you improve this?

Character Count Problem

Write a function called count_chars that accepts a string and returns the number of occurrences of each character in the string.

count_chars('cat') # => {a: 1, c:1, t: 1}
count_chars('hey there') => # {e: 3, h: 2, r: 1, t: 1, y: 1}

One possible solution:

def count_chars(string)
  chars = {}
  string.each_char do |char|
    c = char.downcase # count upper and lowercase as the same letter
    chars[c] ||= 0
    chars[c] += 1
  end
  chars
end

puts count_chars(ARGV[0] || "hello").sort.to_h.inspect

Formatting Output Problem

Write a program that prints out a properly formatted grade-school multiplication table up to 12x12

One possible solution:

(1..12).each do |x|
  (1..12).each do |y|
    printf "%03s ", (x*y)
  end
  puts
end

We're looking to see how comfortable they are with formatting output when necessary, using tools like printf

Simple Text Search Problem

Let's say we have a large legacy static website. All content is in the "html" directory and contains many subdirectories of varying depths with .html files. The product team has asked that we find any phone number references and ensure they are in a consistent format given they presently aren't. Assuming phone numbers are presently formatted as "555-5555" or "555-555-5555" or "(555) 555-5555" how would you obtain a list of all files that need to be changed?

Just trying to see if they are comfortable with regular expressions and command line tools like grep

Hamming Distance Problem

Write a function to calculate the Hamming difference between two strings. This distance is the comparison of how many differences are present in the two. For example, given the following strings:

GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^ ^ ^  ^ ^    ^^

The Hamming distance would be 7.

Here's are some sample test cases:

"A", "A"                          # => 0
"A", "G"                          # => 1
"AG", "CT"                        # => 2
"AGG", "AGA"                      # => 1
"GATACA", "GCATAA"                # => 4
"GGACGGATTCTG", "AGGACGGATTCT"    # => 9

One possible solution:

def self.compute(left_strand, right_strand)
  (0..left_strand.length).count do |i|     
    left_strand[i] != right_strand[i]      
  end                                      
end                                        

Bricks Problem

Implement a function called enough_bricks? that calculates if we can lay bricks out to the desired goal. We have two types of bricks: "big" and "small". Assume big bricks are 5 units wide, and small bricks are one.

Our function should take three arguments: the number of small bricks we have available, the number of big bricks we have available, and our desired goal. Return true or false if the goal is attainable based on the parameters we provide.

enough_bricks?(3, 1, 8) # => true
enough_bricks?(3, 2, 10) # => true
enough_bricks?(15, 2, 12) # => true
enough_bricks?(1, 4, 11) # => true

enough_bricks?(3, 2, 9) # => false
enough_bricks?(2, 3, 3) # => false
enough_bricks?(15, 2, 26) # => false

One possible solution:

BIG_WIDTH = 5
  
def enough_bricks?(small, big, goal)
  # case 1: not enough total bricks       
  total = (big * BIG_WIDTH) + small       
  return false if total < goal            
                                          
  # case 2: not enough small breaks       
  small_needed = goal % BIG_WIDTH         
  small_needed <= small                   
end                                       

OO Animal Kingdom

Model the Animal Kingdom as a class system, e.g. for use in a Virtual Zoo program.

We're looking for their basic grasp of Object Orientated Programming, the animal kingdom is already broken down into scientific classes, so the hope is they would pick up on the parallels and use them:

  • Kingdom
  • Phylum
  • Class
  • Order
  • Family
  • Genus
  • Species

Ruby/Rails

  • Explain to me the difference between a class and module. Do either support multiple inheritance. Tell me about the difference between a symbol and a string (high level). Can you talk to me about the implementation details of each?
  • How does a GET request to a Rails application become a response?
  • What is CSRF? How does Rails mitigate this sort of attack?

Javascript

  • Describe the this keyword in Javascript
  • Make this work:
[1, 2, 3].duplicate() // => [1, 2, 3, 1, 2, 3]

Trying to see if they are familiar with prototype in JS.:

Array.prototype.duplicate = function() { return this.concat(this); }
  • How do you test your Javascript?
  • What are linters? Why are they useful?
  • How do you organize your Javascript (modules/namespaces?)
  • Explain "hoisting" in Javascript
  • Explain closures and how they are useful
  • Explain event bubbling
  • Explain AJAX
  • Explain Same Origin Policy in relation to Javascript.
    • What are some techniques for working around this limitation?
  • Explain JSONP
  • Explain difference between setInterval and setTimeout?
    • How do you stop a function spawned through setInterval

CSS

  • How can we fix the broken layout in this snippet? See how the side bar is collapsing beneath the articles. The designers would like these two columns to be side by side but it doesn't work at the moment. Can you fix it?
  • What is a "box model" in CSS?
  • In what ways are CSS pre-processors like SASS/Less useful?
  • What are CSS "floats"?
    • If I've floated an element and it's not expanding to the height of its children, how can I fix?
    • What does clearing a float do?
  • Can you explain this selector?
[role=navigation] > ul a:not([href^=mailto]) {

}

Personal

  • What technologies are you excited about and would like to learn?
  • What do you like to do for fun?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment