├── diagrams ├── 10 │ ├── .gitkeep │ └── diagrams.xml ├── 01 │ ├── .gitkeep │ └── diagrams.xml ├── 02 │ ├── .gitkeep │ └── diagrams.xml ├── 03 │ └── .gitkeep ├── 04 │ └── .gitkeep ├── 05 │ └── .gitkeep ├── 06 │ └── .gitkeep ├── 07 │ ├── .gitkeep │ └── diagrams.xml ├── 08 │ └── .gitkeep └── 09 │ ├── .gitkeep │ └── diagrams.xml ├── .gitignore ├── README.md ├── exercises ├── levelwidth │ ├── node.js │ ├── index.js │ └── test.js ├── linkedlist │ ├── index.js │ ├── test.js │ └── directions.html ├── maxchar │ ├── index.js │ └── test.js ├── events │ ├── example.html │ ├── index.js │ └── test.js ├── package.json ├── qfroms │ ├── stack.js │ ├── index.js │ └── test.js ├── reversestring │ ├── index.js │ └── test.js ├── validate │ ├── index.js │ ├── node.js │ └── test.js ├── sorting │ ├── index.js │ └── test.js ├── vowels │ ├── index.js │ └── test.js ├── reverseint │ ├── index.js │ └── test.js ├── queue │ ├── index.js │ └── test.js ├── fib │ ├── index.js │ └── test.js ├── stack │ ├── index.js │ └── test.js ├── weave │ ├── queue.js │ ├── index.js │ └── test.js ├── circular │ ├── index.js │ ├── test.js │ └── linkedlist.js ├── palindrome │ ├── index.js │ └── test.js ├── fizzbuzz │ ├── index.js │ └── test.js ├── capitalize │ ├── index.js │ └── test.js ├── matrix │ ├── index.js │ └── test.js ├── pyramid │ ├── index.js │ └── test.js ├── chunk │ ├── index.js │ └── test.js ├── fromlast │ ├── index.js │ ├── test.js │ └── linkedlist.js ├── steps │ ├── index.js │ └── test.js ├── anagrams │ ├── index.js │ └── test.js ├── midpoint │ ├── index.js │ ├── test.js │ └── linkedlist.js ├── bst │ ├── index.js │ └── test.js └── tree │ ├── index.js │ └── test.js └── completed_exercises ├── levelwidth ├── node.js ├── index.js └── test.js ├── package.json ├── qfroms ├── stack.js ├── test.js └── index.js ├── reversestring ├── test.js └── index.js ├── maxchar ├── test.js └── index.js ├── vowels ├── test.js └── index.js ├── weave ├── queue.js ├── index.js └── test.js ├── reverseint ├── index.js └── test.js ├── validate ├── node.js ├── test.js └── index.js ├── fromlast ├── test.js ├── index.js └── linkedlist.js ├── capitalize ├── test.js └── index.js ├── events ├── example.html ├── index.js └── test.js ├── queue ├── index.js └── test.js ├── fib ├── test.js └── index.js ├── stack ├── index.js └── test.js ├── circular ├── index.js ├── test.js └── linkedlist.js ├── palindrome ├── index.js └── test.js ├── midpoint ├── index.js ├── test.js └── linkedlist.js ├── fizzbuzz ├── index.js └── test.js ├── matrix ├── test.js └── index.js ├── anagrams ├── test.js └── index.js ├── steps ├── test.js └── index.js ├── sorting ├── test.js └── index.js ├── bst ├── test.js └── index.js ├── chunk ├── test.js └── index.js ├── pyramid ├── test.js └── index.js ├── tree ├── index.js └── test.js └── linkedlist ├── index.js ├── test.js └── directions.html /diagrams/01/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/02/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/03/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/04/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/05/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/06/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/07/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/08/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/09/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /diagrams/10/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AlgoCasts 2 | 3 | Companion repo to [The Coding Inteview Bootcamp: Algorithms + Data Structures](https://www.udemy.com/course/coding-interview-bootcamp-algorithms-and-data-structure/) 4 | -------------------------------------------------------------------------------- /exercises/levelwidth/node.js: -------------------------------------------------------------------------------- 1 | module.exports = class Node { 2 | constructor(data) { 3 | this.data = data; 4 | this.children = []; 5 | } 6 | 7 | add(data) { 8 | this.children.push(new Node(data)); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /exercises/linkedlist/index.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Implement classes Node and Linked Lists 3 | // See 'directions' document 4 | 5 | class Node {} 6 | 7 | class LinkedList {} 8 | 9 | module.exports = { Node, LinkedList }; 10 | -------------------------------------------------------------------------------- /completed_exercises/levelwidth/node.js: -------------------------------------------------------------------------------- 1 | module.exports = class Node { 2 | constructor(data) { 3 | this.data = data; 4 | this.children = []; 5 | } 6 | 7 | add(data) { 8 | this.children.push(new Node(data)); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /completed_exercises/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /exercises/maxchar/index.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given a string, return the character that is most 3 | // commonly used in the string. 4 | // --- Examples 5 | // maxChar("abcccccccd") === "c" 6 | // maxChar("apple 1231111") === "1" 7 | 8 | function maxChar(str) {} 9 | 10 | module.exports = maxChar; 11 | -------------------------------------------------------------------------------- /exercises/events/example.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 || Function | 16 |Arguments | 17 |Returns | 18 |Directions | 19 |Example | 20 |
| Node.constructor | 25 |(Data, Node) | 26 |Node | 27 |28 | Creates a class instance to represent a node. The node should 29 | have two properties, 'data' and 'next'. Accept both 30 | of these as arguments to the 'Node' constructor, then 31 | assign them to the instance as properties 'data' and 'next'. 32 | If 'next' is not provided to the constructor, then default its 33 | value to be 'null'. 34 | | 35 |
36 |
37 | const n = new Node('There');
38 | n.data // 'Hi'
39 | n.next // null
40 | const n2 = new Node('Hi', n);
41 | n.next // returns n
42 |
43 | |
44 |
| Function | 53 |Arguments | 54 |Returns | 55 |Directions | 56 |Example | 57 |
| constructor | 62 |- | 63 |(LinkedList) | 64 |65 | Create a class to represent a linked list. When created, 66 | a linked list should have *no* head node associated with it. 67 | The LinkedList instance will have one property, 'head', which 68 | is a reference to the first node of the linked list. By default 69 | 'head' should be 'null'. 70 | | 71 |
72 | 73 | const list = new LinkedList(); 74 | list.head // null 75 |76 | |
77 |
| insertFirst | 80 |(data) | 81 |- | 82 |83 | Creates a new Node from argument 'data' and assigns the resulting 84 | node to the 'head' property. Make sure to handle the case in which 85 | the linked list already has a node assigned to the 'head' property. 86 | | 87 |
88 |
89 | const list = new LinkedList();
90 | list.insertFirst('Hi There'); // List has one node
91 |
92 | |
93 |
| size | 96 |- | 97 |(integer) | 98 |99 | Returns the number of nodes in the linked list. 100 | | 101 |
102 |
103 | const list = new LinkedList();
104 | list.insertFirst('a');
105 | list.insertFirst('b');
106 | list.insertFirst('c');
107 | list.size(); // returns 3
108 |
109 | |
110 |
| getFirst | 113 |- | 114 |(Node) | 115 |116 | Returns the first node of the linked list. 117 | | 118 |
119 |
120 | const list = new LinkedList();
121 | list.insertFirst('a');
122 | list.insertFirst('b');
123 | list.getFirst(); // returns Node instance with data 'a'
124 |
125 | |
126 |
| 129 | getLast 130 | | 131 |132 | - 133 | | 134 |135 | (Node) 136 | | 137 |138 | Returns the last node of the linked list 139 | | 140 |
141 |
142 | const list = new LinkedList();
143 | list.insertFirst('a');
144 | list.insertFirst('b');
145 | list.getLast(); // returns node with data 'a'
146 |
147 | |
148 |
| 151 | clear 152 | | 153 |154 | - 155 | | 156 |157 | - 158 | | 159 |160 | Empties the linked list of any nodes. 161 | | 162 |
163 |
164 | const list = new LinkedList();
165 | list.insertFirst('a');
166 | list.insertFirst('b');
167 | list.clear();
168 | list.size(); // returns 0
169 |
170 | |
171 |
| 174 | removeFirst 175 | | 176 |177 | - 178 | | 179 |180 | - 181 | | 182 |183 | Removes only the first node of the linked list. The list's head should 184 | now be the second element. 185 | | 186 |
187 |
188 | const list = new LinkedList();
189 | list.insertFirst('a');
190 | list.insertFirst('b');
191 | list.removeFirst();
192 | list.getFirst(); // returns node with data 'a'
193 |
194 | |
195 |
| 198 | removeLast 199 | | 200 |201 | - 202 | | 203 |204 | - 205 | | 206 |207 | Removes the last node of the chain 208 | | 209 |
210 |
211 | const list = new LinkedList();
212 | list.insertFirst('a');
213 | list.insertFirst('b');
214 | list.removeLast();
215 | list.size(); // returns 1
216 | list.getLast(); // returns node with data of 'b'
217 |
218 | |
219 |
| 222 | insertLast 223 | | 224 |225 | (Data) 226 | | 227 |228 | - 229 | | 230 |231 | Inserts a new node with provided data at the end of the chain 232 | | 233 |
234 |
235 | const list = new LinkedList();
236 | list.insertFirst('a');
237 | list.insertFirst('b');
238 | list.insertLast('c');
239 | list.getLast(); // returns node with data 'C'
240 |
241 | |
242 |
| 245 | getAt 246 | | 247 |248 | (integer) 249 | | 250 |251 | (Node) 252 | | 253 |254 | Returns the node at the provided index 255 | | 256 |
257 |
258 | const list = new List();
259 | list.insertFirst('a');
260 | list.insertFirst('b');
261 | list.insertFirst('c');
262 | list.getAt(1); // returns node with data 'b'
263 |
264 | |
265 |
| 268 | removeAt 269 | | 270 |271 | (integer) 272 | | 273 |274 | - 275 | | 276 |277 | Removes node at the provided index 278 | | 279 |
280 |
281 | const list = new List();
282 | list.insertFirst('a');
283 | list.insertFirst('b');
284 | list.insertFirst('c');
285 | list.removeAt(1);
286 | list.getAt(1); // returns node with data 'a'
287 |
288 | |
289 |
| 292 | insertAt 293 | | 294 |295 | (Data, integer) 296 | | 297 |298 | - 299 | | 300 |301 | Create an insert a new node at provided index. 302 | If index is out of bounds, add the node to the end 303 | of the list. 304 | | 305 |
306 |
307 | const list = new List();
308 | list.insertFirst('a');
309 | list.insertFirst('b');
310 | list.insertFirst('c');
311 | list.insertAt('Hi', 1)
312 | list.getAt(1); // returns node with data 'Hi'
313 |
314 | |
315 |
| 318 | forEach 319 | | 320 |321 | (function) 322 | | 323 |324 | - 325 | | 326 |327 | Calls the provided function with every node of the chain 328 | | 329 |
330 |
331 | const list = new List();
332 |
333 | list.insertLast(1);
334 | list.insertLast(2);
335 | list.insertLast(3);
336 | list.insertLast(4);
337 |
338 | list.forEach(node => {
339 | node.data += 10;
340 | });
341 | list.getAt(0); // Returns node with data '11'
342 |
343 | |
344 |
| 347 | for...of Loop 348 | | 349 |350 | - 351 | | 352 |353 | - 354 | | 355 |356 | Linked list should be compatible as the subject of a 'for...of' loop 357 | | 358 |
359 |
360 | const list = new List();
361 |
362 | list.insertLast(1);
363 | list.insertLast(2);
364 | list.insertLast(3);
365 | list.insertLast(4);
366 |
367 | for (let node of list) {
368 | node.data += 10;
369 | }
370 |
371 | node.getAt(1); // returns node with data 11
372 |
373 | |
374 |
| Function | 16 |Arguments | 17 |Returns | 18 |Directions | 19 |Example | 20 |
| constructor | 25 |(Data, Node) | 26 |Node | 27 |28 | Creates a class instance to represent a node. The node should 29 | have two properties, 'data' and 'next'. Accept both 30 | of these as arguments to the 'Node' constructor, then 31 | assign them to the instance as properties 'data' and 'next'. 32 | If 'next' is not provided to the constructor, then default its 33 | value to be 'null'. 34 | | 35 |
36 |
37 | const n = new Node('Hi');
38 | n.data // 'Hi'
39 | n.next // null
40 | const n2 = new Node('There', n);
41 | n.next // returns n
42 |
43 | |
44 |
| Function | 53 |Arguments | 54 |Returns | 55 |Directions | 56 |Example | 57 |
| constructor | 62 |- | 63 |(LinkedList) | 64 |65 | Create a class to represent a linked list. When created, 66 | a linked list should have *no* head node associated with it. 67 | The LinkedList instance will have one property, 'head', which 68 | is a reference to the first node of the linked list. By default 69 | 'head' should be 'null'. 70 | | 71 |
72 | 73 | const list = new LinkedList(); 74 | list.head // null 75 |76 | |
77 |
| insertFirst | 80 |(data) | 81 |- | 82 |83 | Creates a new Node from argument 'data' and assigns the resulting 84 | node to the 'head' property. Make sure to handle the case in which 85 | the linked list already has a node assigned to the 'head' property. 86 | | 87 |
88 |
89 | const list = new LinkedList();
90 | list.insertFirst('Hi There'); // List has one node
91 |
92 | |
93 |
| size | 96 |- | 97 |(integer) | 98 |99 | Returns the number of nodes in the linked list. 100 | | 101 |
102 |
103 | const list = new LinkedList();
104 | list.insertFirst('a');
105 | list.insertFirst('b');
106 | list.insertFirst('c');
107 | list.size(); // returns 3
108 |
109 | |
110 |
| getFirst | 113 |- | 114 |(Node) | 115 |116 | Returns the first node of the linked list. 117 | | 118 |
119 |
120 | const list = new LinkedList();
121 | list.insertFirst('a');
122 | list.insertFirst('b');
123 | list.getFirst(); // returns Node instance with data 'a'
124 |
125 | |
126 |
| 129 | getLast 130 | | 131 |132 | - 133 | | 134 |135 | (Node) 136 | | 137 |138 | Returns the last node of the linked list 139 | | 140 |
141 |
142 | const list = new LinkedList();
143 | list.insertFirst('a');
144 | list.insertFirst('b');
145 | list.getLast(); // returns node with data 'a'
146 |
147 | |
148 |
| 151 | clear 152 | | 153 |154 | - 155 | | 156 |157 | - 158 | | 159 |160 | Empties the linked list of any nodes. 161 | | 162 |
163 |
164 | const list = new LinkedList();
165 | list.insertFirst('a');
166 | list.insertFirst('b');
167 | list.clear();
168 | list.size(); // returns 0
169 |
170 | |
171 |
| 174 | removeFirst 175 | | 176 |177 | - 178 | | 179 |180 | - 181 | | 182 |183 | Removes only the first node of the linked list. The list's head should 184 | now be the second element. 185 | | 186 |
187 |
188 | const list = new LinkedList();
189 | list.insertFirst('a');
190 | list.insertFirst('b');
191 | list.removeFirst();
192 | list.getFirst(); // returns node with data 'a'
193 |
194 | |
195 |
| 198 | removeLast 199 | | 200 |201 | - 202 | | 203 |204 | - 205 | | 206 |207 | Removes the last node of the chain 208 | | 209 |
210 |
211 | const list = new LinkedList();
212 | list.insertFirst('a');
213 | list.insertFirst('b');
214 | list.removeLast();
215 | list.size(); // returns 1
216 | list.getLast(); // returns node with data of 'b'
217 |
218 | |
219 |
| 222 | insertLast 223 | | 224 |225 | (Data) 226 | | 227 |228 | - 229 | | 230 |231 | Inserts a new node with provided data at the end of the chain 232 | | 233 |
234 |
235 | const list = new LinkedList();
236 | list.insertFirst('a');
237 | list.insertFirst('b');
238 | list.insertLast('c');
239 | list.getLast(); // returns node with data 'C'
240 |
241 | |
242 |
| 245 | getAt 246 | | 247 |248 | (integer) 249 | | 250 |251 | (Node) 252 | | 253 |254 | Returns the node at the provided index 255 | | 256 |
257 |
258 | const list = new List();
259 | list.insertFirst('a');
260 | list.insertFirst('b');
261 | list.insertFirst('c');
262 | list.getAt(1); // returns node with data 'b'
263 |
264 | |
265 |
| 268 | removeAt 269 | | 270 |271 | (integer) 272 | | 273 |274 | - 275 | | 276 |277 | Removes node at the provided index 278 | | 279 |
280 |
281 | const list = new List();
282 | list.insertFirst('a');
283 | list.insertFirst('b');
284 | list.insertFirst('c');
285 | list.removeAt(1);
286 | list.getAt(1); // returns node with data 'a'
287 |
288 | |
289 |
| 292 | insertAt 293 | | 294 |295 | (Data, integer) 296 | | 297 |298 | - 299 | | 300 |301 | Create an insert a new node at provided index. 302 | If index is out of bounds, add the node to the end 303 | of the list. 304 | | 305 |
306 |
307 | const list = new List();
308 | list.insertFirst('a');
309 | list.insertFirst('b');
310 | list.insertFirst('c');
311 | list.insertAt('Hi', 1)
312 | list.getAt(1); // returns node with data 'Hi'
313 |
314 | |
315 |
| 318 | forEach 319 | | 320 |321 | (function) 322 | | 323 |324 | - 325 | | 326 |327 | Calls the provided function with every node of the chain and the index 328 | of the node. 329 | | 330 |
331 |
332 | const list = new List();
333 |
334 | list.insertLast(1);
335 | list.insertLast(2);
336 | list.insertLast(3);
337 | list.insertLast(4);
338 |
339 | list.forEach((node, index) => {
340 | node.data += 10;
341 | });
342 | list.getAt(0); // Returns node with data '11'
343 |
344 | |
345 |
| 348 | for...of Loop 349 | | 350 |351 | - 352 | | 353 |354 | - 355 | | 356 |357 | Linked list should be compatible as the subject of a 'for...of' loop 358 | | 359 |
360 |
361 | const list = new List();
362 |
363 | list.insertLast(1);
364 | list.insertLast(2);
365 | list.insertLast(3);
366 | list.insertLast(4);
367 |
368 | for (let node of list) {
369 | node.data += 10;
370 | }
371 |
372 | node.getAt(1); // returns node with data 11
373 |
374 | |
375 |