0% found this document useful (0 votes)
101 views

Coding Interview Rules

This document outlines 10 heuristics for solving coding questions in interviews: 1) Use a heap data structure for finding top/maximum/minimum/closest 'K' elements among 'N' elements. 2) Use binary search or two pointers for sorted arrays/lists. 3) Use backtracking or breadth-first search for trying all combinations or permutations. 4) Use breadth-first search or depth-first search for trees and graphs problems. 5) Convert recursive solutions to iterative using a stack. 6) For O(n^2) time and O(1) space, optimize to O(n) time and O(n) space using hashmap/set or O(n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Coding Interview Rules

This document outlines 10 heuristics for solving coding questions in interviews: 1) Use a heap data structure for finding top/maximum/minimum/closest 'K' elements among 'N' elements. 2) Use binary search or two pointers for sorted arrays/lists. 3) Use backtracking or breadth-first search for trying all combinations or permutations. 4) Use breadth-first search or depth-first search for trees and graphs problems. 5) Convert recursive solutions to iterative using a stack. 6) For O(n^2) time and O(1) space, optimize to O(n) time and O(n) space using hashmap/set or O(n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

10 Golden Rules

for
Solving Coding Questions
in
Interviews

DesignGurus.io
Heuristic # 1

If we are dealing with


top/maximum/minimum/closest
'K' elements among 'N' elements, we
will be using a Heap.

DesignGurus.io
Heuristic # 2

If the given input is a sorted array


or a list, we will either be using
Binray Search or the Two Pointers
strategy.

DesignGurus.io
Heuristic # 3

If we need to try all combinations


(or permutations) of the input, we
can either use Backtracking or
Breadth First Search.

DesignGurus.io
Heuristic # 4

Most of the questions related to


Trees or Graphs can be solved
either through Breadth First
Search or Depth First Search.

DesignGurus.io
Heuristic # 5

Every recursive solution can be


converted to an iterative solution
using a Stack.

DesignGurus.io
Heuristic # 6

For a problem involving arrays, if


there exists a solution in O(n^2)
time and O(1) space, there must
exist two other solutions: 1) Using a
HashMap or a Set for O(n) time
and O(n) space, 2) Using sorting
for O(n log n) time and O(1) space.

DesignGurus.io
Heuristic # 7

If a problem is asking for


optimization (e.g., maximization
or minimization), we will be using
Dynamic Programming.

DesignGurus.io
Heuristic # 8

If we need to find some common


substring among a set of strings,
we will be using a HashMap or a
Trie.

DesignGurus.io
Heuristic # 9

If we need to search/manipulate
a bunch of strings, Trie will be the
best data structure.

DesignGurus.io
Heuristic # 10

If the problem is related to a


LinkedList and we can't use extra
space, then use the Fast & Slow
Pointer approach.

DesignGurus.io
➡ Follow these techniques to
distinguish yourself from others! A
number of these approaches are
discussed in "Grokking the
Coding Interview" from
DesignGurus.io

DesignGurus.io

You might also like