Bianca Gandolfo PRO
Slide decks for learning JavaScript
A Practical Intro to Data Structures for Interviews
slides.com/bgando/intro-ds-1
@BiancaGando
What to expect
Step | Process |
---|---|
Resume / Application | |
Coding Challenge | |
Recruiter Phone Screen | |
Technical Phone Screen | |
Onsite Interview |
What to expect
Step | Process |
---|---|
Resume / Application | Resume skimmer, manual reading, or submitted by recommendation |
Coding Challenge | HackerRank, create a demo app, Add a feature to a demo app |
Recruiter Phone Screen | Friendly, marketing company, questions about why you are leaving, what you are working on, what you want next, etc. |
Technical Phone Screen | Code in a collabedit or google doc Pair program on adding a feature to a codebase High-level questions about your domain and projects |
Onsite Interview | Similar to above except in person and 3-6hrs long, sometimes a bit harder |
Interview Skills at Each Step
Step | Looking For | Over-achieve |
---|---|---|
Resume / Application | Gauges relevant experience | |
Coding Challenge | Clean, correct code | |
Recruiter Phone Screen | Interest in role, company, culture fit | |
Technical Phone Screen | Gauge tech ability & fit | |
Onsite Interview | Gauge tech ability & fit |
Interview Skills at Each Step
Step | Looking For | Over-achieve |
---|---|---|
Resume / Application | Relevant experience | Recommendation from someone |
Coding Challenge | Clean, correct code | Use a linter, ensure you clearly Understand the problem, add tests and descriptive comments |
Recruiter Phone Screen | Interest in role, company, culture fit | Read the engineering blog and relevant press about the company Ask engaging questions, have highlights ready |
Technical Phone Screen | Tech ability & fit | Have a conversational tone, communicate the entire way. Be able to discuss previous projects in-depth |
Onsite Interview | Tech ability & fit | Know your DS, your language of choice, and be their friend |
Some Reasons you Bombed
Step | Looking For | Glaring problem |
---|---|---|
Resume / Application | Relevant experience | |
Coding Challenge | Clean, correct code | |
Recruiter Phone Screen | Interest in role, company, culture fit | |
Technical Phone Screen | Tech ability & fit | |
Onsite Interview | Tech ability & fit |
Some Reasons you Bombed
Step | Looking For | Glaring problem |
---|---|---|
Resume / Application | Relevant experience | Relevant experience is buried, grammar issues, no role fit |
Coding Challenge | Clean, correct code | Messy, unorganized code, didn't solve the challenge, missed details |
Recruiter Phone Screen | Interest in role, company, culture fit | Communication-based: Offended recruiter, didn't seem interested in company |
Technical Phone Screen | Tech ability & fit | Inability to describe past project high-level implementation details, not communicative, frustrated |
Onsite Interview | Tech ability & fit | Thought-process was not clear, lack of CS fundamentals, communication |
What is a data structure?
Why should you care?
Common Interview DS
DS | Common Uses | FEM Course |
---|---|---|
Arrays & Strings | ordered data, words | Part 2 (this one) |
Hash Tables | optimization | Part 2 (this one) |
Linked Lists | data insert/delete | Part 2 (this one) |
Stacks/Queues | creative aux DS | Part 2 (this one) |
Trees, Heaps | hierarchical data | Part 3 |
Graphs | complex relationships | Part 4 |
What will we cover today?
1. Background
2. Implementation
3. Analysis
4. Gain experience and intuition
Stack / Queue
Linked List
Hash Table
Array / String
How to be effective
Rule #1 don't aim to memorize, this will not help!
Rule #2 find themes, but don't jump to conclusions
Rule #3 practice with a timer, speed matters
Rule #3.5 actually practice, reading doesn't count
Rule #4 communicate and be nice
Stack / Queue
Linked List
Hash Table
Array / String
Intro to our
Data Structures
@BiancaGando
Stacks
Queues
Linked Lists
Hash Tables
Arrays
Strings
Stack / Queue
Linked List
Hash Table
Array / String
stores items in a last-in, first-out (LIFO) order
stores items in a first-in, first-out (FIFO) order
Pros |
---|
Fast operations |
Stack / Queue
Linked List
Hash Table
Array / String
JavaScript engines have a call stack and message queue that executes your code at runtime
When you hit 'undo' in your text editor or 'back' in your browser, you are using a stack
const stack = [1,2,3,4];
stack.push(5);
// [1,2,3,4,5]
stack.pop();
// -> 5
// [1,2,3,4]
const queue = [1,2,3,4];
queue.enqueue(5);
// [1,2,3,4,5]
queue.dequeue();
// -> 1
// [2,3,4,5]
Stack / Queue
Linked List
Hash Table
Array / String
organizes items sequentially, with each item storing a pointer to the next
Pros | Cons |
---|---|
Fast operations on the ends | Costly lookups |
Flexible size |
Stack / Queue
Linked List
Hash Table
Array / String
Linked Lists are often the underlying data structure for a stack or queue.
You can implement a Least Recently Used cache using a linked list.
Hash tables often use linked lists to handle collisions
const linkedlist = {
head: {
value: 1
next: {
value: 2
next: {
value: 3
next: null
}
}
}
}
Stack / Queue
Linked List
Hash Table
Array / String
Without looking up anything, draw the following data structures:
- Stack
- Queue
- Linked List
Tweet @BiancaGando and @FrontendMasters
for feedback and laughs
Stack / Queue
Linked List
Hash Table
Array / String
organizes data for quick look up on values for a given key.
Pros | Cons |
---|---|
Fast lookups | Slow worst-case lookups |
Flexible keys | Unordered |
Single-directional lookups |
Stack / Queue
Linked List
Hash Table
Array / String
{ }
Map
Set
Stack / Queue
Linked List
Hash Table
Array / String
organizes items sequentially in memory
Pros | Cons |
---|---|
Fast lookups | Slow insert |
Fast appends | Slow deletes |
Stack / Queue
Linked List
Hash Table
Array / String
[]
Stack / Queue
Linked List
Hash Table
Array / String
Without looking up anything, draw the following data structures:
- Hash Table
- Array
- String
Tweet @BiancaGando and @FrontendMasters
for feedback and laughs
Implemention
@BiancaGando
Stack / Queue
Linked List
Hash Table
Array / String
/** Class representing a Stack. */
class Stack {
constructor() {
this.storage = {};
}
/*
* Adds a new value at the end of the
* stack
* @param {*} value the value to push
*/
push() {
}
/*
* Removes the value at the end of the stack and returns it
* @return {*} the last and newest value in the stack
*/
pop() {
}
/*
* Returns the value at the end of the stack without removing it
* @return {*} the last and newest value in the stack
*/
peek() {
}
}
Stack / Queue
Linked List
Hash Table
Array / String
/** Class representing a Queue. */
class Queue {
constructor() {
this.storage = {};
}
/*
* Enqueues a new value at the end
* of the queue
* @param {*} value - the value to
* enqueue
*/
enqueue() {
}
/*
* Dequeues the value from the beginning of the queue and returns it
* @return {*} the first and oldest value in the queue
*/
dequeue() {
}
/*
* Returns the value at the beginning of the queue without removing it from the queue
* @return {*} value the first and oldest value in the queue
*/
peek() {
}
}
Stack / Queue
Linked List
Hash Table
Array / String
/** Class representing a Linked List */
class LinkedList {
constructor() {
this.storage = {};
}
/*
* Inserts a new value to the end of the linked list
* @param {*} value - the value to insert
*/
insert() {
}
/*
* Deletes a node
* @param {*} node - the node to remove
* @return {*} value - the deleted node's value
*/
remove() {
}
/*
* Removes the value at the end of the linked list
* @return {*} - the removed value
*/
removeTail() {
}
/*
* Searches the linked list and returns true if it contains the value passed
* @param {*} value - the value to search for
* @return {boolean} - true if value is found, otherwise false
*/
contains() {
}
/*
* Checks if a node is the head of the linked list
* @param {{prev:Object|null, next:Object|null}} node - the node to check
* @return {boolean} - true if node is the head, otherwise false
*/
isHead() {
}
/*
* Checks if a node is the tail of the linked list
* @param {{prev:Object|null, next:Object|null}} node - the node to check
* @return {boolean} - true if node is the tail, otherwise false
*/
isTail() {
}
}
Stack / Queue
Linked List
Hash Table
Array / String
/** Class representing a Hash Table */
class HashTable {
constructor() {
this.storage = [];
}
/*
* Inserts a new key-value pair
* @param {string} key - the key associated
* with the value
* @param {*} value - the value to insert
*/
insert() {
}
/*
* Deletes a key-value pair
* @param {string} key - the key associated with the value
* @return {*} value - the deleted value
*/
remove() {
}
/*
* Returns the value associated with a key
* @param {string} key - the key to search for
* @return {*} - the value associated with the key
*/
retrieve() {
}
/*
* Hashes string value into an integer that can be mapped to an array index
* @param {string} str - the string to be hashed
* @param {number} n - the size of the storage array
* @return {number} - an integer between 0 and n
*/
_hash(str, n) {
let sum = 0;
for (let i = 0; i < str.length; i++)
sum += str.charCodeAt(i) * 3
return sum % n;
}
}
Stack / Queue
Linked List
Hash Table
Array / String
/** Class representing an Aray, a fictional data
* structure similar to an array except that the
* underlying storage is a string
*/
class Aray {
constructor() {
this.storage = '';
}
/*
* Pushes a value at the end of the aray
* @param {string} value - the value to insert
* @return {number} - the length of the aray
*/
push() {
}
/*
* Pops off the last value of the aray
* @return {string} value - the popped value
*/
pop() {
}
/*
* Returns the length of the aray
* @return {number} - the length of the aray
*/
length() {
}
}
Common Interview Questions
@BiancaGando
Stack / Queue
Linked List
Hash Table
Array / String
Stack / Queue
Linked List
Hash Table
Array / String
Delete the following:
1 - a node in the middle of the linked list
2 - a node with only a variable pointing at that node
3 - a duplicate
Stack / Queue
Linked List
Hash Table
Array / String
Stack / Queue
Linked List
Stack / Queue
Linked List
Hash Table
Array / String
Recap
@BiancaGando
Stack / Queue
Linked List
Hash Table
Array / String
Stack/ Queue |
Linked List | Array/ String |
|
---|---|---|---|
Reversing | linear | linear | linear |
Sorting | tower of Hanoi | not typical | merge, quik |
Traversing | not typical | linear | linear |
Merging, sorted | not typical | linear | linear |
Merging, range | not typical | not typical | if sorted, O(n) |
Interleaving | not typical | linear | linear |
Partitioning | not typical | linear | linear |
Rotating | not typical | linear | linear |
Edit distance | not typical | not typical | varies |
Shuffling | not typical | varies | varies |
Stack / Queue
Linked List
Hash Table
Array / String
Stack/ Queue |
Linked List | Hash Table | Array/ String |
|
---|---|---|---|---|
Searching | linear | linear | linear | linear |
Searching, sorted | log(n) | log(n) | NA | log(n) |
Min/Max | stack, O(1) | stack, O(1) | stack, O(1) | stack, O(1) |
Min/Max, sorted | in-place, O(1) | in-place, O(1) | NA | in-place, O(1) |
Unique | HT, O(n) | HT, O(n) | default | HT, O(n) |
Unique, sorted | in-place, O(n) | in-place, O(n) | NA | in-place, O(n) |
Permutations |
Stack / Queue
Linked List
Hash Table
Array / String
Things to consider
in-place / side effects
preserving original order
Set vs Map vs Object
lengths of 0 and 1
off-by-ones
optimization vs readability
what other information could you ask for?
Further Resources
On Frontend Masters:
Upcoming: Interview Prep course
Brian Holt's CS in 5hrs
Geeks for Geeks
https://github.com/jwasham/coding-interview-university
Cracking the Coding Interview
Hacker Rank / Leetcode
Interviewing.io & Pramp
Stack / Queue
Linked List
Hash Table
Array / String
By Bianca Gandolfo
WIP