Monday, January 11, 2016

Cracking the Algorithm & Coding Interview - Gayle McDowell - Push yourself!



http://www.slideshare.net/gayle2/cracking-the-algorithm-coding-interview-svcc
Strong CS fundamentals
Analytical skills
Make tradeoffs
Push through hard problems
Communication
How you think

Preparation
Implement DS/Algorithms
MASTER Big O
Practice with interview questions
Code on paper/whiteboard
Mock interviews

Expectations & Evaluation
What is not expected:
To know the answers
To solve immediately
To code perfectly

Be excited about hard problems
More than just “correct”
Drive!
Keep trying when stuck
Write real code
Show me how you think!

RELATIVE
Not a “metric” / timer
No one is perfect!
step 1:
Listen (for clues)
What’s the clue?
Anagram server
Ex: rates -> aster, stare, taser, tears

Clue: why is it on a server?

Step 2:
Draw an Example
Big Enough + General Purpose

Ex: Intersection of Two Sorted Arrays
Most people draw something like this:
[1, 12, 15, 19]
[2, 12, 13, 20]

Too small
Too special-case-y
same size, one common element, same index

Better:
  [1, 12, 15, 19, 20, 21]
  [2, 15, 17, 19, 21, 25, 27]

Big
No special cases

Step 3:
Brute Force / Naive
Stupid & terrible is okay!

Step 4:
Optimize
Walk through brute force
Look for optimizations

Techniques to Develop Algorithms
Optimize
BUD
Space/time
Do it yourself

Solve
Recursion
Solve “incorrectly”
Other data structures

(A) Look for BUD
Bottlenecks
Unnecessary work
Duplicated work

What’s the bottleneck?
Ex: counting the intersection
  [1, 12, 15, 19, 20, 21]
  [2, 15, 17, 19, 21, 25, 27]
Bottleneck: searching

What’s unnecessary?
Ex: a3 + b3 = c3 + d3    (1 <= a, b, c, d <= 1000
Unnecessary: looking for d
What’s duplicated?
Duplicated: c, d pairs


(B) Space/Time Tradeoffs
Hash tables & other data structures
Precomputing

Space/Time Tradeoffs  Hash tables
Find # pairs with sum
  INPUT: array = [5, 15, 8, 9, 3, 2, -1, 4]
              sum = 7
  OUTPUT: 3
    pairs = (5, 2), (8, -1), (3, 4)
Put items into hash table

Space/Time Tradeoffs  Precomputing
Find rectangle at origin w biggest sum

Find permutations of s within b
s = abbc
b = babcabbacaabcbabcacbb

Find them!
… now how did you actually do it?

(D) Recursion / Base Case & Build
Subsets of a set
{}  {}
{a}  {}, {a}
{a, b}  {}, {a}, {b}, {a, b}
{a, b, c}  …
Subsets of {S1…Sn-1} + Sn to each

(E) Solve “incorrectly”
Develop incorrect solution
Identify why precisely it’s incorrect
Repair
(& Repeat)

Random node in BST
Try: flip coin
Coin = Heads
 Branch Left
Coin = Tails
 Branch Right

Try: pick random # 0 through n-1
R = 0
 Return root
1 <= R <= left.size
 Branch left
R > left.size
 Branch right

(F) Other Data Structures
Giving out phone numbers
“I want any available number”
“I want this number”
Try: sorted array? Sorted linked list? Hash table? BST?

step 5:
Walk Through
Know the variables
and when they change

How to Write Whiteboard Code
Modularized
Error cases / TODOs
Good variables

Write straight
Top-left corner
Use arrows if needed
step 7 - Testing

FIRST Analyze
What’s it doing? Why?
Anything that looks weird?
Error hot spots
THEN use test cases
Small test cases
Edge cases
Bigger test cases

Final Thoughts
Be a great teammate.
Be a great engineer.
http://www.slideshare.net/gayle2/cracking-the-coding-interview-40140660
The Perfect Candidate
How to become a more perfect dev candidate
Coursera
Bootcamps
Read lots.
Write lots.

Hackathons
Diversity languages.
Independent projects.

Length:
1 – 2  pages.
1 – 2 lines per bullet.
3 – 6 bullets per company.
Projects.
Clear accomplishments.
Technical…
But not overwhelming.

Knowledge Questions
Know your stuff.
Be cautious about what you list.
If you don’t know, admit it.
Derive it if possible.

“Design Google Maps”
Strong foundation in CS
Analytic skills/intelligence.
Ability to make tradeoffs.
Discussion/teamwork ability.
How you think about a problem.

7. Testing
Conceptual - does it make sense?
Weird stuff (x = len – 2)
Hot spots (end of list)

Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts