Cracking the Coding Interview: 189 Programming Questions and Solutions 6th Edition by Gayle Laakmann McDowell

Cracking the Coding Interview

I am not a recruiter. I am a software engineer. And as such, I know what it's like to be asked to whip up brilliant algorithms on the spot and then write flawless code on a whiteboard. I've been through this as a candidate and as an interviewer.

Cracking the Coding Interview, 6th Edition is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I've coached and interviewed hundreds of software engineers. The result is this book.

Learn how to uncover the hints and hidden details in a question, discover how to break down a problem into manageable chunks, develop techniques to unstick yourself when stuck, learn (or re-learn) core computer science concepts, and practice on 189 interview questions and solutions.

These interview questions are real; they are not pulled out of computer science textbooks. They reflect what's truly being asked at the top companies, so that you can be as prepared as possible.

WHAT'S INSIDE?

  • 189 programming interview questions, ranging from the basics to the trickiest algorithm problems.
  • A walk-through of how to derive each solution, so that you can learn how to get there yourself.
  • Hints on how to solve each of the 189 questions, just like what you would get in a real interview.
  • Five proven strategies to tackle algorithm questions, so that you can solve questions you haven't seen.
  • Extensive coverage of essential topics, such as big O time, data structures, and core algorithms.
  • A behind the scenes look at how top companies like Google and Facebook hire developers.
  • Techniques to prepare for and ace the soft side of the interview: behavioral questions.
  • For interviewers and companies: details on what makes a good interview question and hiring process.
Cracking the Coding Interview: 189 Programming Questions and Solutions

More about this book

Something's Wrong

We walked out of the hiring meeting frustrated—again. Of the ten candidates we reviewed that day, none would receive offers. Were we being too harsh, we wondered?

I in particular, was disappointed. We had rejected one of my candidates. A former student. One I had referred. He had a 3.73 GPA from the University of Washington, one of the best computer science schools in the world, and had done extensive work on open-source projects. He was energetic. He was creative. He was sharp. He worked hard. He was a true geek in all the best ways.

But I had to agree with the rest of the committee: the data wasn't there. Even if my emphatic recommendation could sway them to reconsider, he would surely get rejected in the later stages of the hiring process. There were just too many red flags.

Although he was quite intelligent, he struggled to solve the interview problems. Most successful candidates could fly through the first question, which was a twist on a well-known problem, but he had trouble developing an algorithm. When he came up with one, he failed to consider solutions that optimized for other scenarios. Finally, when he began coding, he flew through the code with an initial solution, but it was riddled with mistakes that he failed to catch. Though he wasn't the worst candidate we’d seen by any measure, he was far from meeting the “bar.” Rejected.

When he asked for feedback over the phone a couple of weeks later, I struggled with what to tell him. Be smarter? No, I knew he was brilliant Be a better coder? No, his skills were on par with some of the best I’d seen.

Like many motivated candidates, he had prepared extensively. He had read K&R's classic C book, and he’d reviewed CLRS’ famous algorithms textbook. He could describe in detail the myriad of ways of balancing a tree, and he could do things in C that no sane programmer should ever want to do.

I had to tell him the unfortunate truth: those books aren't enough. Academic books prepare you for fancy research, and they will probably make you a better software engineer, but they're not sufficient for interviews. Why? I'll give you a hint: Your interviewers haven't seen red-black trees since they were in school either.

To crack the coding interview, you need to prepare with real interview questions. You must practice on real problems and learn their patterns. It's about developing a fresh algorithm, not memorizing existing problems.

Cracking the Coding Interview is the result of my first-hand experience interviewing at top companies and later coaching candidates through these interviews. It is the result of hundreds of conversations with candidates. It is the result of the thousands of questions contributed by candidates and interviewers. And it's the result of seeing so many interview questions from so many firms. Enclosed in this book are 189 of the best interview questions, selected from thousands of potential problems.

My Approach

The focus of Cracking the Coding Interview is algorithm, coding, and design questions. Why? Because while you can and will be asked behavioral questions, the answers will be as varied as your resume. Like-wise, while many firms will ask so-called “trivia” questions (e.g., “What is a virtual function?”), the skills developed through practicing these questions are limited to very specific bits of knowledge. The book will briefly touch on some of these quest ions to show you what they're like, but I have chosen to allocate space to areas where there's more to learn.

Product details

  • Publisher : CareerCup; 6th edition (July 1, 2015)
  • Language : English
  • Paperback : 687 pages
  • ISBN-10 : 0984782869
  • ISBN-13 : 978-0984782857

Table of contents

  • Introduction
  • I. The Interview Process
    • Why?
    • How Questions are Selected
    • It's All Relative
    • Frequently Asked Questions
  • II. Behind the Scenes
    • The Microsoft Interview
    • The Amazon Interview
    • The Google Interview
    • The Apple Interview
    • The Facebook Interview
    • The Palantir Interview
  • III. Special Situations
    • Experienced Candidates
    • Testers and SDETs
    • Product (and Program) Management
    • Dev Lead and Managers
    • Startups
    • Acquisitions and Acquihires
    • For Interviewers
  • IV. Before the Interview
    • Getting the Right Experience
    • Writing a Great Resume
    • Preparation Map
  • V. Behavioral Questions
    • Interview Preparation Grid
    • Know Your Technical Projects
    • Responding to Behavioral Questions
    • So, tell me about yourself
  • VI. Big O
    • An Analogy
    • Time Complexity
    • Space Complexity
    • Drop the Constants
    • Drop the Non-Dominant Terms
    • Multi-Part Algorithms: Add vs. Multiply
    • Amortized Time
    • Log N Runtimes
    • Recursive Runtimes
    • Examples and Exercises
  • VII. Technical Questions
    • How to Prepare
    • What You Need To Know
    • Walking Through a Problem
    • Optimize & Solve Technique #1: Look for BUD
    • Optimize & Solve Technique #2: DIY (Do It Yourself)
    • Optimize & Solve Technique #3: Simplify and Generalize
    • Optimize & Solve Technique #4: Base Case and Build
    • Optimize & Solve Technique #5: Data Structure Brainstorm
    • Best Conceivable Runtime (BCR)
    • Handling Incorrect Answers
    • When You've Heard a Question Before
    • The “Perfect” Language for Interviews
    • What Good Coding Looks Like
    • Don't Give Up!
  • VIII. The Offer and Beyond
    • Handling Offers and Rejection
    • Evaluating the Offer
    • Negotiation
    • On the Job
  • IX. Interview Questions
    • Data Structures
    • Chapter 1 Arrays and Strings
      • Hash Tables
      • ArrayList & Resizable Arrays
      • StringBuilder
    • Chapter 2 Linked Lists
      • Creating a Linked List
      • Deleting a Node from a Singly Linked List
      • The 'Runner' Technique
      • Recursive Problems
    • Chapter 3 Stacks and Queues
      • Implementing a Stack
      • Implementing a Queue
    • Chapter 4 Trees and Graphs
      • Types of Trees
      • Binary Tree Traversal
      • Binary Heaps (Min-Heaps and Max-Heaps)
      • Tries (Prefix Trees)
      • Graphs
      • Graph Search
    • Concepts and Algorithms
    • Chapter 5 Bit Manipulation
      • Bit Manipulation By Hand
      • Bit Facts and Tricks
      • Two's Complement and Negative Numbers
      • Arithmetic vs. Logical Right Shift
      • Common Bit Tasks: Getting and Setting
    • Chapter 6 Math and Logic Puzzles
      • Prime Numbers
      • Probability
      • Start Talking
      • Develop Rules and Patterns
      • Worst Case Shifting
      • Algorithm Approaches
    • Chapter 7 Object-Oriented Design
      • How to Approach
      • Design Patterns
    • Chapter 8 Recursion and Dynamic Programming
      • How to Approach
      • Recursive vs. Iterative Solutions
      • Dynamic Programming & Memoization
    • Chapter 9 System Design and Scalability
      • Handling the Questions
      • Design: Step-By-Step
      • Algorithms that Scale: Step-By-Step
      • Key Concepts
      • Considerations
      • There is no “perfect” system
      • Example Problem
    • Chapter 10 Sorting and Searching
      • Common Sorting Algorithms
      • Searching Algorithms
    • Chapter 11 Testing
      • What the Interviewer Is Looking For
      • Testing a Real World Object
      • Testing a Piece of Software
      • Testing a Function
      • Troubleshooting Questions
    • Knowledge Based
    • Chapter 12 C and C++
      • Gasses and Inheritance.
      • Constructors and Destructors
      • Virtual Functions
      • Virtual Destructor
      • Default Values
      • Operator Overloading
      • Pointers and References
      • Templates
    • Chapter 13 Java
      • How to Approach
      • Overloading vs. Overriding
      • Collection Framework
    • Chapter 14 Databases
      • SOL Syntax and Variations
      • Denormalized vs. Normalized Databases
      • SOL Statements
      • Small Database Design
      • Large Database Design
    • Chapter 15 Threads and Locks
      • Threads in Java
      • Synchronization and Locks
      • Deadlocks and Deadlock Prevention
    • Additional Review Problems
    • Chapter 16 Moderate
    • Chapter 17 Hard
  • X. Solutions
    • Data Structures
    • Concepts and Algorithms
    • Knowledge Based
    • Additional Review Problems
  • XI. Advanced Topics
    • Useful Math
    • Topological Sort
    • Dijkstra's Algorithm
    • Hash Table Collision Resolution
    • Rabin-Karp Substring Search
    • AVL Trees
    • Red-Black Trees
    • MapReduce
    • Additional Studying
  • XII. Code Library
    • HashMapList<T, E>
    • TreeNode (Binary Search Tree)
    • LinkedListNode (Linked List)
    • Trie & TrieNode
  • XIII. Hints
    • Hints for Data Structures
    • Hints for Concepts and Algorithms
    • Hints for Knowledge-Based Questions
    • Hints for Additional Review Problems
  • XIV. About the Author

Author Bio

Gayle Laakmann McDowell is the founder and CEO of CareerCup and the author of Cracking the PM Interview and Cracking the Tech Career.

Her background is in software development. She has worked as a software engineer at Google, Microsoft, and Apple. At Google, she interviewed hundreds of software engineers and evaluated thousands of hiring packets on the hiring committee. She holds a B.S.E. and M.S.E. in computer science from the University of Pennsylvania and an MBA from the Wharton School.

She now consults with tech companies to improve their hiring process and with startups to prepare them for acquisition interviews.

The Self-Taught Programmer: The Definitive Guide by Cory Althoff

The Self-Taught Programmer: The Definitive Guide to Programming Professionally

The Self-Taught Programmer: The Definitive Guide to Programming Professionally by Cory Althoff I am a self-taught programmer. After a year of self-study, I learned to program well enough to land a job as a software engineer II at eBay. Once I got there, I realized I was severely under-prepared. I was overwhelmed by the amount of things I needed to know but hadn't learned yet. My journey learning to program, and my experience at my first job as a software engineer were the inspiration for this book. This book is not just about learning to program; although you will learn to code. If you want to program professionally, it is not enough to learn to code; that is why, in addition to helping you learn to program, I also cover the rest of the things you need to know to program professionally that classes and books don't teach you. "The Self-taught Programmer" is a roadmap, a guide to take you from writing your first Python program, to passing your first technical…

Read more…

Hands-On Machine Learning 2nd Edition by Aurélien Géron

Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow

Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems 2nd Edition by Aurélien Géron Through a series of recent breakthroughs, deep learning has boosted the entire field of machine learning. Now, even programmers who know close to nothing about this technology can use simple, efficient tools to implement programs capable of learning from data. This practical book shows you how. By using concrete examples, minimal theory, and two production-ready Python frameworks—Scikit-Learn and Tensor Flow—author Aurélien Géron helps you gain an intuitive understanding…

Read more…

Python Crash Course, 2nd Edition by Eric Matthes

Python Crash Course, 2nd Edition

Python Crash Course, 2nd Edition A Hands-On, Project-Based Introduction to Programming by Eric Matthes Second edition of the best-selling Python book in the world. A fast-paced, no-nonsense guide to programming in Python. Updated and thoroughly revised to reflect the latest in Python code and practices. Python Crash Course is the world’s best-selling guide to the Python programming language. This fast-paced, thorough introduction to programming with Python…

Read more…