Skip to content

Instantly share code, notes, and snippets.

@magic003
Last active December 30, 2015 18:09
Show Gist options
  • Save magic003/c9eed6094e9ef07af496 to your computer and use it in GitHub Desktop.
Save magic003/c9eed6094e9ef07af496 to your computer and use it in GitHub Desktop.
This gist lists the things important for preparing a technical interview.
  • Consider using HashMap when comparing two strings or arrays.
  • When handling string problems, ask if it is ASCII. Use an array of length 256 if it is.
  • When comparing two strings or arrays, sort them first.
  • Using StringBuffer for the temporary result for string concatenate.
  • Prepend a dummy node for linked list problems.
  • Remember integer might be negative!
  • Computer cannot accurately represent float/double, use epsilon for equality check.

Common tricks:

  • Interval intersection: 1) sort by start point, binary search the end point 2) sort both start and end points, go through the array, for start point i++, for end point i--.
  • For interval scheduling, use greedy algorithm: earliest time first.
  • Median for a random generated integer stream, using a min and a max heap.
  • For kth smalless element, using the quicksort partition or a k maxheap.
  • Consider suffix tree or trie, when dealing with string match problems.
  • Consider segment tree, when needs preprocessor and min/max value in a range.
  • Randomly generate m elements from array of n, using the array shuffle algorithm.
  • Preoder, inorder, postorder tree traverse, using a stack and another pointer to remember what is the prev node.
  • If elements have slightly difference with other, construct a graph and find the hamilton cycle or Eulerian cycle.
  • When looking for string with the same characters, sort the string first.
  • While we can use DP or Kadane's algorithm to get the maximum subarray, it cannot be used directly for minimum subarray. It can be used by changing the sign, find the maximum and change the sign back.
  • When finish writing code in an interview, "run" (or walk through) the code to test it.
  • Tell the interviewer if previously heard the problem.
  • Review the preparation grid for behavioral questions
  • Keep the resume to one page
  • Write strong bullets for employment history
  • List most languages you've used, but add your experience level.
  • For US positions, do not include age, marital status, or nationality.

Data Structures

  • HashMap
  • Heap/PriorityQueue

Strategies

  • Binary search: achieve log(n) complexity
  • Dynamic programming
  • Greedy
  • Backtracing

Common tricks

Mistake

  • When dealing with arrays, pay attention to empty array and index out of bound cases.
  • When dealing with two arrays or linked list, consider the case that one is shorter and don't forget the carry value after the loop.
  • For easy problem, pay attention to special/base cases.
  • When dealing with integers in string representation, consider leading 0s and overflow problems.
  • Regular expression matching, don't forget the "a*" in the pattern.
  • Don't forget to increase/decrease index in the loop.
  • When dealing integer division, consider the negative case.
  • When get the permutation or combination of a collection, don't forget to avoid duplications.
  • When dealing with multiplication, mod and power, don't forget negative integers.
  • When traversing a binary tree using stack, don't forget to push right before left.

TODO

  • String matching algorithms: KMP, BM and etc.

Should get familar with the following concepts and practise again and again.

Data Structure

  • Binary search tree (E extends Comparable, null check for min() and max())
  • Hash table implementing using array and binary search tree. (Generic, load factor and rehash)
  • Linked list (inner Node class as static)
  • Stack using array and linked list
  • Queue using array and linked list (font/rare set to 0 at start, isFull() and isEmpty(), circular)
  • Tree
  • Graph (adjacency list vs adjacency matrix, store vertices in hashmap)
  • In-order, pre-order, post-order and level-order tree traversal (pre-order and post-order cannot recover the tree)
  • Red-Black trees and AVL trees (AVL slow insertion/removal, but fast search. Rotation)
  • Tries (prefix tree, have multiple children)
  • Graph traversal: breadth first search and depth first search (Queue for BFS, stack/recursion for DFS. DONOT pop in DFS if need to handle children first)
  • Bit manipulation (Get, set, clear and update bit)
  • Power of 2 table

Object-Oriented Design

  • Singleton Pattern (static getInstance(), thread-safe)
  • Factory Method Pattern (create instance based on type, defer creation to subclass)

Algorithm

  • Resursion
  • Dynamic Programming
  • Merge sort (recursive sort and merge)
  • Quicksort
  • Bucket Sort (divide into several buckets and sort each one)
  • Bubble sort
  • Selection sort
  • Raidx sort (buckets, sort from the least significant digit)
  • Heapsort (siftDown, heapify and sort)
  • Binary search
  • String match algorithms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment