You are on page 1of 1

1 Listen 2 Example

CRACKING THE
CODING
Pay very close attention to any info in the Most examples are too small or are special
problem description. You probably need it cases. Debug your example. Is there any way
all for an optimal algorithm. it’s a special case? Is it big enough?

SKILLS
BUD Optimization 3 Brute Force
Bottlenecks
Created By Gayle Get a brute-force solution as soon as possible. Don’t
Unnecessary Work
Laakmann McDowell worry about developing an efficient algorithm
Duplicated Work yet. State a naive algorithm and its runtime, then
optimize from there. Don’t code yet though!
Best Conceivable
Runtime (BCR) 7 Test
BCR is the runtime you know you
Test in this order:
4 Optimize
can’t beat. For example, if asked
to compute the intersection of Walk through your brute force with BUD
1. Conceptual test. Walk through your code
two sets, you know you can’t beat optimization or try some of these ideas:
like you would for a detailed code review.
O(|A|+|B|).  Look for any unused info. You usually need all
2. Unusual or non-standard code.
the information in a problem.
5 Approaches 3. Hot spots, like arithmetic and null nodes.
 Solve it manually on an example, then reverse
4. Small test cases. It’s much faster than a big
 BUD: Look for bottlenecks, engineer your thought process. How did you
test case and just as effective.
unnecessary work, solve it?
duplicated work. 5. Special cases and edge cases.
 Solve it “incorrectly” and then think about why
And when you find bugs, fix them carefully! the algorithm fails. Can you fix those issues?
 DIY: Do It Yourself
 Simplify & Generalize:  Make a time vs. space tradeoff. Hash tables are
Solve a simpler version. 6 Implement especially useful!

 Base Case & Build: Solve for


Your goal is to write beautiful code.
the base cases then build
from there.
Modularize your code from the beginning 5 Walk Through
and refactor to clean up anything that isn’t
 Data Structure Brainstorm: beautiful. Now that you have an optimal solution, walk
Try various data structures. through your approach in detail. Make sure you
understand each detail before you start coding.

What You Need To Know


Data Structures: Hash Tables, Linked Lists, Stacks, Queues,
1 Trees, Tries, Graphs, Vectors, Heaps.
Exercises:
 Implement data structures & algorithms from scratch.

Algorithms: Quick Sort, Merge Sort, Binary Search, Breadth-  Prove to yourself the runtime of the major algorithms.
2 First Search, Depth-First Search.

Concepts: Big-O Time, Big-O Space, Recursion & Memoization,


3 Probability, Bit Manipulation. Do not…
 Do not ignore information given. Info is there for a reason.
 Do not try to solve problems in your head. Use an example!
Books by  Do not push through code when confused. Stop and think!
Gayle  Do not dive into code without interviewer “sign off.”
© CareerCup.com

You might also like