You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/front-end-interview-guidebook/contents/algorithms/en-US.mdx
+53-53Lines changed: 53 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,9 @@ There are a ton of resources out there that cover algorithmic coding interviews
18
18
19
19
## Examples
20
20
21
-
- Reverse a linked list.
22
-
- Determine if a string contains balanced brackets.
23
-
- Determine how many substrings in a string are palindromes.
21
+
- Reverse a linked list
22
+
- Determine if a string contains balanced brackets
23
+
- Determine how many substrings in a string are palindromes
24
24
25
25
## How to prepare
26
26
@@ -48,78 +48,78 @@ Be aware of the common JavaScript operations and their time complexities.
48
48
49
49
### `Array`
50
50
51
-
| Operation | Time complexity|
52
-
| --------------------------- | --------------- |
53
-
|`Array.prototype.concat()`|O(m + n)|
54
-
|`Array.prototype.every()`|O(n)|
55
-
|`Array.prototype.fill()`|O(n)|
56
-
|`Array.prototype.filter()`|O(n)|
57
-
|`Array.prototype.find()`|O(n)|
58
-
|`Array.prototype.pop()`|O(1)|
59
-
|`Array.prototype.push()`|O(1)|
60
-
|`Array.prototype.reduce()`|O(n)|
61
-
|`Array.prototype.reverse()`|O(n)|
62
-
|`Array.prototype.shift()`|O(n)|
63
-
|`Array.prototype.slice()`|O(n)|
64
-
|`Array.prototype.some()`|O(n)|
65
-
|`Array.prototype.sort()`|O(nlgn)|
66
-
|`Array.prototype.splice()`|O(n)|
67
-
|`Array.prototype.unshift()`|O(m + n)|
51
+
Array operations and their time complexity:
52
+
53
+
-`Array.prototype.concat()`: O(m + n)
54
+
-`Array.prototype.every()`: O(n)
55
+
-`Array.prototype.fill()`: O(n)
56
+
-`Array.prototype.filter()`: O(n)
57
+
-`Array.prototype.find()`: O(n)
58
+
-`Array.prototype.pop()`: O(1)
59
+
-`Array.prototype.push()`: O(1)
60
+
-`Array.prototype.reduce()`: O(n)
61
+
-`Array.prototype.reverse()`: O(n)
62
+
-`Array.prototype.shift()`: O(n)
63
+
-`Array.prototype.slice()`: O(n)
64
+
-`Array.prototype.some()`: O(n)
65
+
-`Array.prototype.sort()`: O(nlgn)
66
+
-`Array.prototype.splice()`: O(n)
67
+
-`Array.prototype.unshift()`: O(m + n)
68
68
69
69
<sup>*</sup> `n` is the number of elements in the array and `m` is the number of
70
70
elements to be added.
71
71
72
72
### `Map`
73
73
74
-
| Operation | Time complexity |
75
-
| --- | --- |
76
-
|`Map.prototype.clear()`|O(n)|
77
-
|`Map.prototype.delete()`|O(1)|
78
-
|`Map.prototype.entries()`|O(1) because it returns an iterator. Getting all the entries will take O(n) time. |
79
-
|`Map.prototype.forEach()`|O(n)|
80
-
|`Map.prototype.get()`|O(1)|
81
-
|`Map.prototype.has()`|O(1)|
82
-
|`Map.prototype.keys()`|O(1) because it returns an iterator. Getting all the keys will take O(n) time. |
83
-
|`Map.prototype.set()`|O(1)|
84
-
|`Map.prototype.values()`|O(1) because it returns an iterator. Getting all the values will take O(n) time. |
74
+
Map operations and their time complexity:
75
+
76
+
-`Map.prototype.clear()`: O(n)
77
+
-`Map.prototype.delete()`: O(1)
78
+
-`Map.prototype.entries()`: O(1) because it returns an iterator. Getting all the entries will take O(n) time
79
+
-`Map.prototype.forEach()`: O(n)
80
+
-`Map.prototype.get()`: O(1)
81
+
-`Map.prototype.has()`: O(1)
82
+
-`Map.prototype.keys()`: O(1) because it returns an iterator. Getting all the keys will take O(n) time
83
+
-`Map.prototype.set()`: O(1)
84
+
-`Map.prototype.values()`: O(1) because it returns an iterator. Getting all the values will take O(n) time
85
85
86
86
<sup>*</sup> `n` is the number of keys in the map.
87
87
88
88
### `Set`
89
89
90
-
| Operation | Time complexity |
91
-
| --- | --- |
92
-
|`Set.prototype.add()`|O(1)|
93
-
|`Set.prototype.clear()`|O(n)|
94
-
|`Set.prototype.delete()`|O(1)|
95
-
|`Set.prototype.entries()`|O(1) because it returns an iterator. Getting all the entries will take O(n) time. |
96
-
|`Set.prototype.forEach()`|O(n)|
97
-
|`Set.prototype.has()`|O(1)|
98
-
|`Set.prototype.keys()`|O(1) because it returns an iterator. Getting all the keys will take O(n) time. |
99
-
|`Set.prototype.values()`|O(1) because it returns an iterator. Getting all the values will take O(n) time. |
90
+
Set operations and their time complexity:
91
+
92
+
-`Set.prototype.add()`: O(1)
93
+
-`Set.prototype.clear()`: O(n)
94
+
-`Set.prototype.delete()`: O(1)
95
+
-`Set.prototype.entries()`: O(1) because it returns an iterator. Getting all the entries will take O(n) time
96
+
-`Set.prototype.forEach()`: O(n)
97
+
-`Set.prototype.has()`: O(1)
98
+
-`Set.prototype.keys()`: O(1) because it returns an iterator. Getting all the keys will take O(n) time
99
+
-`Set.prototype.values()`: O(1) because it returns an iterator. Getting all the values will take O(n) time
100
100
101
101
<sup>*</sup> `n` is the number of elements in the set.
102
102
103
-
## Algorithmic coding interview rubrics
103
+
## Evaluation axes
104
104
105
105
During algorithmic coding interviews, interviewers are evaluating candidates on the following skills:
106
106
107
-
-**Problem solving**: Use a systematic and logical approach to understanding and addressing a problem. Break down the problem into smaller independent problems. Evaluate different approaches and their tradeoffs.
108
-
-**Technical competence**: Ability to translate solutions into working code and demonstrating a strong understanding of the language being used.
109
-
-**Communication**: Ask questions to clarify details and clearly explain one's approach and considerations.
110
-
-**Verification**: Identify various scenarios to test the code against, including edge cases. Be able to diagnose and fix any issues that arise.
107
+
-**Problem solving**: Use a systematic and logical approach to understanding and addressing a problem. Break down the problem into smaller independent problems. Evaluate different approaches and their tradeoffs
108
+
-**Technical competence**: Ability to translate solutions into working code and demonstrating a strong understanding of the language being used
109
+
-**Communication**: Ask questions to clarify details and clearly explain one's approach and considerations
110
+
-**Verification**: Identify various scenarios to test the code against, including edge cases. Be able to diagnose and fix any issues that arise
111
111
112
112
## Useful tips
113
113
114
-
-**Wishful thinking**. JavaScript's standard library doesn't have some useful data structures and algorithms like queue, heap, binary search, which can make your life easier during JavaScript coding interviews. However, you can ask the interviewer if you can pretend such a data structure/algorithm exists and use it directly in your solution without implementing it.
115
-
-**Pure functions**. Aim to write pure functions which have the benefit of reusability and modularity, aka functions which don't rely on state outside of the function and doesn't cause side effects.
116
-
-**Choose data structures wisely.** Pay attention to your choice of data structures and be aware of the time complexities of the code. Be familiar with the time/space complexities of the basic JavaScript Array, Object, Set, Map operations should you want to use them in your solution. Some of these time/space complexities differ across languages. Don't write code that runs in O(n<sup>2</sup>) if it can accomplished in O(n) runtime with the use of hash maps.
117
-
-**Recursion edge cases**.
118
-
- If you have identified that solving the question requires recursion, ask about the input size and how to handle the case of recursion stack overflow. Usually you won't have to handle it but raising this issue is a good signal.
119
-
- Nested deep data structures can have recursive references to itself, which makes certain operations like serialization much trickier. Ask the interviewer if you have to handle such cases. Usually you won't have to handle it but raising this issue is a good signal.
114
+
-**Wishful thinking**: JavaScript's standard library doesn't have some useful data structures and algorithms like queue, heap, binary search, which can make your life easier during JavaScript coding interviews. However, you can ask the interviewer if you can pretend such a data structure/algorithm exists and use it directly in your solution without implementing it.
115
+
-**Pure functions**: Aim to write pure functions which have the benefit of reusability and modularity, aka functions which don't rely on state outside of the function and doesn't cause side effects.
116
+
-**Choose data structures wisely**: Pay attention to your choice of data structures and be aware of the time complexities of the code. Be familiar with the time/space complexities of the basic JavaScript Array, Object, Set, Map operations should you want to use them in your solution. Some of these time/space complexities differ across languages. Don't write code that runs in O(n<sup>2</sup>) if it can accomplished in O(n) runtime with the use of hash maps.
117
+
-**Recursion edge cases**:
118
+
-**Clarifying input size**: If you have identified that solving the question requires recursion, ask about the input size and how to handle the case of recursion stack overflow. Usually you won't have to handle it but raising this issue demonstrates thoughtfulness.
119
+
-**Cyclic structures**: Nested deep data structures can have recursive references to itself, which makes certain operations like serialization and traversal more tricky. Ask the interviewer if you have to handle such cases. Usually you won't have to handle it but raising this issue demonstrates thoughtfulness.
120
120
121
121
## Practice questions
122
122
123
-
Blind 75 is a famous and concise list of algorithm questions by Yangshun Tay. You can practice the [Blind 75 question list on GreatFrontEnd](/interviews/blind75).
123
+
Blind 75 is a famous and concise list of algorithm questions curated by [Yangshun Tay](https://www.linkedin.com/in/yangshun/). You can practice the [Blind 75 question list on GreatFrontEnd](/interviews/blind75).
124
124
125
125
GreatFrontEnd also provides some [general practice questions for Data Structures and Algorithms](/questions/formats/algo-coding) where you can practice implementing common data structures ([Stack](/questions/algo/stack), [Queue](/questions/algo/queue)) and algorithms ([Binary Search](/questions/algo/binary-search), [Merge Sort](/questions/algo/merge-sort)), etc in JavaScript.
0 commit comments