This repository contains a collection of common interview problems:
- anagrams
- binary search tree (BST)
- validate
- capitalize
- chunk
- fibonacci
- memoize
- fizzbuzz
- islandcount
- matchbraces
- maxchar
- mergesort
- palindrome
- queue
- pyramid
- reverseint
- reversestring
- steps
- tree
- breadth first
- depth first
- levelwidth
Most of the problems in this repository were taken from the Udemy course, "The Coding Interview Bootcamp," by Stephen Grider.
Grider's Github repository, including Jest tests, can be found here:
https://github.com/StephenGrider/algocasts
Each problem includes a test suite written with Jest.
To run the test suite for a given problem in its directory:
$ jest <directory>/test.js --watch
Hit Ctrl + C to stop the Jest test runner.
To debug a problem in Node:
- Add a debugger statement in the code:
function reverse (str) {
let reversed = '';
for (let char of str) {
reversed = char + reversed;
debugger;
}
return reversed;
}
- Call the function within the code:
reverse('Greetings!');
- In the console, run the following command:
$ node inspect _<filename.js>_
-
Node will execute the program in debug node, pausing execution on the first line of the file. Type 'C' to continue with execution of code. Execution will stop at the debugger statement.
-
Type repl to enter REPL mode and inspect different variables.
-
Type a variable name to see its value at that point in the execution.
-
Type Ctrl + C to leave the REPL debug session.
-
When debugging is finished, remove the debugger statement and manual function call within the file.
Used git rebase to pull the changes from origin and rewind the HEAD:
git pull -r origin master
Tree Data Structure
Traversal
Iterating through the elements (nodes) of a tree.
Types
1. Breadth-First Traversal
Start at top of tree (root) and move across from left to right. Then move down to the next level and repeat.
2. Depth-First Traversal
Start at top of tree and move down the left-hand branch to the bottom, then back up and down. Try to reach the bottom of tree as fast as possible.