More cheatsheet tips

This commit is contained in:
Yangshun Tay
2017-10-14 20:32:11 +08:00
parent bfa350013c
commit 08e23d0b6c
2 changed files with 20 additions and 7 deletions

View File

@ -29,6 +29,8 @@ If you are interested in how data structures are implemented, check out [Lago](h
## General Tips
Clarify any assumptions you made subconsciously. Many questions are under-specified on purpose.
Always validate input first. Check for invalid/empty/negative/different type input. Never assume you are given the valid parameters. Alternatively, clarify with the interviewer whether you can assume valid input (usually yes), which can save you time from writing code that does input validation.
Are there any time/space complexity requirements/constraints?
@ -58,7 +60,7 @@ Data structures can be augmented to achieve efficient time complexities across d
Hashmaps are probably the most commonly used data structure for algorithm questions. If you are stuck on a question, your last resort can be to enumerate through the possible data structures (thankfully there aren't that many of them) and consider whether each of them can be applied to the problem. This has worked for me sometimes.
If you are cutting corners in your code, state that out loud to your interviewer and say what you would do in a non-interview setting (no time constraints). E.g., I would write a regex to parse this string rather than using `split()` which does not cover all cases.
If you are cutting corners in your code, state that out loud to your interviewer and say what you would do in a non-interview setting (no time constraints). E.g., I would write a regex to parse this string rather than using `split()` which may not cover all cases.
## Sequence
@ -191,7 +193,7 @@ You can be given a list of edges and tasked to build your own graph from the edg
- Adjacency list.
- Hashmap of hashmaps.
Some inputs look like they are trees but they are actually graphs. In that case you will have to handle cycles and keep a set of visited nodes when traversing.
A tree-like diagram could very well be a graph that allows for cycles and a naive recursive solution would not work. In that case you will have to handle cycles and keep a set of visited nodes when traversing.
#### Graph search algorithms: