Tips to crack coding interviews

  1. ask relevant questions before attempting to solve
  2. break the problem into similar/smaller known problems
  3. briefly discuss brute force approach, if required
  4. where applicable, use
    1. math
    2. sorting
    3. searching
    4. traversal
    5. recursion
    6. bit manipulation
    7. dynamic programming
    8. greedy approach
    9. divide and conquer
    10. backtracking
  5. before implementing your algorithm
    1. discuss it with the interviewer
    2. discuss it’s time and space complexity
    3. see if it can be improved based on above discussion
  6. write test cases (before code!)
  7. start small, test immediately
  8. write functions that are
    1. reusable
    2. loosely coupled
    3. small and do only one thing!
  9. avoid
    1. gotos
    2. unnecessary variables
    3. unnecessary/many/nested if-elses
  10. always
    1. validate input
    2. check return codes
    3. handle corner cases
    4. trace your code with test cases before telling the interviewer – done!