Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
77 views

Coding Interview Cheat Sheet

The document provides an overview of different algorithm and data structure techniques to solve coding interview problems. It includes techniques for graph problems like shortest path, minimum spanning tree, and topological sort. It also covers tree traversal, sorting, dynamic programming, and searching algorithms.

Uploaded by

Harshpreet Kaur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Coding Interview Cheat Sheet

The document provides an overview of different algorithm and data structure techniques to solve coding interview problems. It includes techniques for graph problems like shortest path, minimum spanning tree, and topological sort. It also covers tree traversal, sorting, dynamic programming, and searching algorithms.

Uploaded by

Harshpreet Kaur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Problem Type

Coding Interview Cheat Sheet

Algorithum / Data Graph / Grid


Structure to Solve
the Problem

Minimum cost to Find minimum Counting Clusters of


Deepcopy Graph (or Directed graph with Shortest path
connect nodes operations / steps / Tree Depth First Search Nodes
linked list) prerequisites between nodes
(weighted graph) transformations

Union Find data


Preorder Inorder
structure (disjoint
Postorder
Recursive graph Is this a normal sets)
Topological Sort Is the graph
traversal with visited spanning tree No Breadth First Search Level Order Traversal
(Kahn's Algorithum) weighted?
dictionary problem?
No
Yes No
Yes

Need to optimize BFS for Count subarrays with


Minimum Spanning Kruskal's Algorithum Continuous Subarray
shortest path? A* (BFS, but replace one "occurrence"
Tree (Kruskal's but use some Yes
Are there negitive No queue with heap)
Algorithum) imaginary nodes
weights?

Yes
Look for each
Problem asking for possible occurrence
sorting based on Bellman Ford Prefix Sum Sliding Window and count subarrays
Dijkstra's Algorithm containing that
special criteria Algorithm
occurrence

Python: Pass key


Language specific function that returns Branching decisions and
Subsets of an array
sorting tools tuple with elements in looking for min/max
order of priority

Min / Max x elements


Range of possible of array
answers that can Dynamic
divided into two Looking at 2 elements Find closest elements Programming Python 'combinations'
Nothing else works? Backtracking
sections at a time between two sorted lists function

Boundary between Better than linear


halfs of array search time
Two Pointer QuickSelect Top Down Recrusion
Greedy Algorithm Sort the array Heap Bottom Up
Technique Algorithum + Memoization

Binary Search Find next element Need more pracitce?


Check for Cycle in Reduce Space Compress val out of Problem Involves Rolling Window of greater than each index
Linked List Complexity array Prefixes Events (or prev element less
Schedule a mock coding
than) interview with me

bisect_left(val) bisect_right(val) List of <index, val> TreeMap (Linked Monotonic Stack (not
Fast Pointer + Slow
Returns index of first Retruns index of first Overwrite the input pairs, excluding one PrefixTree (Trie) HashMap, Orded a stack, created with http://tiny.cc/e416wz
Pointer
item >= val item > val val Dictionary) a stack)
Coding Interview - Helpful Tips & Strategies
Helpful Python Features Spaced Repetition Strategy
If you're going to spend a lot of time preparing for coding interviews, I think it's worth while to learn Python. Start Here
It's easy to learn, easy to write, and has a lot of helpful features that can make it much easier to solve
problems. Below is a list of some helpful features in Python.

List comprehensions can save time by using much shorter syntax to create a list
Do a coding interview 20 minutes or less and no hints Done with that
Tutorial: http://tinyurl.com/2uek6vxt problem problem
The combination and permutation functions can save a lot of time by returning all the
combinations or permuations for a given list of elements
More than 20 minutes or need hints This strategy helps you get better at
Tutorial: http://tinyurl.com/3aan5kby
problems that you struggle with.
lru_cache can be used to quickly optimize certain functions. It is often used to solve
dynamic programming problems using a top down approach. Lookup solution for
Repeating the same problem after
Tutorial: http://tiny.cc/opj0wz problem waiting several days helps you
remember the solution to that
bisect_left and bisect_right are quick ways to binary serach a sorted list problem in the long term. If you do
3 days later
Tutorial: http://tiny.cc/pwj0wz this for problems that you either
Nested functions can help make your code readable and maintainable needed help solving or took you too
Implement solution long to solve, you will quickly
Tutorial: http://tiny.cc/jxj0wz (don't copy paste) improve in the areas that you are
You can easily return multiple values from a function as a tuple weak.
Tutorial: http://tiny.cc/dyj0wz
Key functions can be used to easily sort a list based on complex criteria
Set a reminder to
Tutorial: http://tiny.cc/dyj0wz redo this problem 3
days from now

Graphs and Grids


Many coding interview problems involve a grid. It can be helpful
to think of a grid like a graph where each cell in the grid is a
node with edges connecting it to neighboring cells.

Many techniques and algorithms that can be applied to a


graph can also be applied to grids. Depth First Search,
Breadth First Search, etc
Need more pracitce?
A B C
Schedule a mock
A B C coding interview
with me
D E F D E F

G H I
G H I
http://tiny.cc/e416wz

You might also like