# Coding Interview Prep

## Steps

1. Understand the question
   1. Ask questions to clarify the question.
   2. **State a concrete example (input + output) of the problem.** After understanding the question, the first thing to do is draw examples. Find a typical simple example and some simple corner case examples. By analyzing the example, we may get an idea about the rule behind.
   3. **Ask the interviewer what time and space complexity he would like in the solution.** It can help you identify if the interviewer cares more about the thinking process or the best solution.
2. Solve the problem (think out loud)
   1. Work on the example to find the idea
   2. Start from the brute force solution
   3. Improve with a better solution
      1. Find a better data structure
      2. Find a better algorithmic technique
      3. Apply tricks for the data structure/algorithmic technique
   4. Work on corner cases
      1. Write unit test?
3. Analyze time and space complexity

## Best Practices

1. Skip implementing anything that is trivial. Use basic libraries for parts that are not the main algorithm. Ask the interviewer if it is OK. If it's not, write another function for it.
2. Handle top-level algorithm first, then the functions you used in the main algorithm but are not defined. Add TODO comments for the part that you want to come back to. Make sure let the interviewer know it.
3. Assume valid inputs. It's not the core problem to check if inputs are valid. So clarify this assumption with the interviewer and take it for granted.
4. Whiteboard coding is different.
   1. Skip documentation since it takes longer to write on whiteboard.
   2. Keep identifiers short and have a convention for identifiers, e.g. i, j for array indices, A, B for arrays, s for string, d for dictionary, etc.

## Tips for Python

1. Testing == is faster than testing >= or <=. So whenever we can narrow down to ==, don't use >= or <=.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lei-d.gitbook.io/leetcode/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
