Tips to crack coding interviews

  1. Ask relevant follow up questions
    1. Collect enough details about the problem
      1. Constraints & special properties often offer hints
    2. Don’t jump to conclusions and solutions immediately
    3. Always remember, devils are in the details
  2. Briefly discuss brute force approach, if required
  3. Map or break the problem into similar/smaller/known problems
    1. Do NOT invent a new/fancy data structure or algorithm
  4. Classify the problem as
    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
    11. Comparator
  5. Apply appropriate data structures (or a combination of)
    1. Arrays
    2. Stacks
    3. Queues
    4. Linked Lists
    5. Hash Tables
    6. Balanced BSTs
    7. MinHeap/MaxHeap
    8. Disjoint Set Union
    9. Tries (Prefix/Suffix Trees)
    10. Each data structure has its own strengths and weaknesses
      1. Identify the “pain points” in the problem
      2. Deploy the right (combination of) data structures for each pain point
  6. 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
  7. Write test cases (before code!)
  8. Start small, test immediately
  9. Write functions that are
    1. Reusable
    2. Loosely coupled
    3. Small and do only one thing!
  10. Avoid
    1. Gotos
    2. Unnecessary variables
    3. Multiple return statements
    4. Unnecessary/many/nested if-elses
  11. Always
    1. Validate input
    2. Indent your code
    3. Use proper names (for functions and variables)
    4. Check return codes
    5. Handle corner cases
    6. Trace your code with test cases before telling the interviewer – done!
  12. Clearing design and behavioral interviews requires genuine experience
    1. Build as much (voluntary) stuff as possible using math, data structures and algorithms
    2. Have enough success and failure stories to talk about