Algorithms

Problem Solving Steps

  1. Communication: The goal is to solve real-world problems collaboratively with the interviewer.
  2. Clarify the Objective: Confirming what is asked is very important. For example, if the problem requires returning values instead of indices, then storing index information is meaningless.
    • Identify boundary cases.
    • Ask valuable questions.
    • Don’t rush to code; first confirm you are solving the correct problem.
  3. Formulate the Problem: To solve algorithm questions, you need to build a formula that describes how to get the result. Then look at all known conditions (such as whether the data is sorted, or any useful data characteristics. You can even preprocess data by youself). This helps decide how the formula converges and whether to use loops or recursion.
  4. Explain Your Approach: Before coding, explain your thought process to the interviewer and get confirmation.
  5. Code:
    • Use a consistent coding style. Use meaningful variable names, and comments.
    • Avoid premature optimization; focus on correctness first.
    • If you are stuck, try to simplify the problem or break it down into smaller parts.
  6. Test Your Code: After coding, run several test cases including edge cases. Run the code manually step by step.
  7. Optimize: Improve time and space complexity if possible. Dont forget that.
Read more