mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-04-23 18:11:04 +08:00
contents: add promotional content within contents
This commit is contained in:
@@ -15,6 +15,8 @@ keywords:
|
||||
sidebar_label: Techniques to solve questions
|
||||
---
|
||||
|
||||
import InDocAd from './\_components/InDocAd';
|
||||
|
||||
The biggest fear most candidates will have during a coding interview is: what if I get stuck on the question and don't know how to do it? Fortunately, there are structured ways to approach coding interview questions that will increase your chances of solving them. From how to find a solution or approach, to optimizing time and space complexity, here are some of the top tips and best practices that will help you solve coding interview questions.
|
||||
|
||||
## How to find solutions to coding interview problems
|
||||
@@ -47,6 +49,8 @@ How do you [validate if a tree is a valid Binary Search Tree](https://leetcode.c
|
||||
|
||||
Coming up with more examples is something useful you can do regardless of whether you are stuck or not. It helps you to reinforce your understanding of the question, prevents you from prematurely jumping into coding, helps you to identify a pattern which can be generalized to any input, which is the solution! Lastly, the multiple examples can be used as test cases at the end when verifying your solution.
|
||||
|
||||
<InDocAd />
|
||||
|
||||
### 4. Break the question down into smaller independent parts
|
||||
|
||||
If the problem is large, start with a high-level function and break it down into smaller constituting functions, solving each one separately. This prevents you from getting overwhelmed with the details of doing everything at once and keeps your thinking structured.
|
||||
@@ -98,6 +102,8 @@ These are the data structures to keep in mind and try, in order of frequency the
|
||||
|
||||
In future we will add tips on how to better identify the most relevant data structures and routines based on the problem.
|
||||
|
||||
<InDocAd />
|
||||
|
||||
## How to optimize your approach or solution
|
||||
|
||||
After you've come up with an initial solution to the coding interview problem, your interviewer would most likely prompt you to optimize the solution by asking "Can we do better". The following techniques help you further optimize the time and space complexity of your solution:
|
||||
@@ -239,6 +245,8 @@ def contains_string(search_term, strings):
|
||||
|
||||
This is considered a micro-optimization and most of the time, `strings` won't be empty, but I'm using it to illustrate the example where you don't have to do certain computations if they aren't needed. This also applies to initialization of objects that you will need in your code (usually hash tables). If the input is empty, there's no need to initialize any variables!
|
||||
|
||||
<InDocAd />
|
||||
|
||||
### How to optimize space complexity
|
||||
|
||||
Most of the time, time complexity is more important than space complexity. But when you have already reached the optimal time complexity, the interviewer might ask you to optimize the space your solution is using (if it is using extra space). Here are some techniques you can use to improve the space complexity of your code.
|
||||
|
||||
Reference in New Issue
Block a user