borislavib / coding-interview-university

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coding Interview University

Table of Contents

---------------- Everything below this point is optional ----------------

Additional Resources


How to use it

Everything below is an outline, and you should tackle the items in order from top to bottom.

Create a new branch so you can check items like this, just put an x in the brackets: [x]

Fork a branch and follow the commands below

Fork the GitHub repo https://github.com/jwasham/coding-interview-university by clicking on the Fork button

Clone to your local repo

git clone git@github.com:<your_github_username>/coding-interview-university.git

git checkout -b progress

git remote add jwasham https://github.com/jwasham/coding-interview-university

git fetch --all

Mark all boxes with X after you completed your changes

git add .

git commit -m "Marked x"

git rebase jwasham/main

git push --set-upstream origin progress

git push --force

More about GitHub-flavored markdown

Don't feel you aren't smart enough

Interview Process & General Interview Prep

Pick One Language for the Interview

You can use a language you are comfortable in to do the coding part of the interview, but for large companies, these are solid choices:

  • Python

Here is an article I wrote about choosing a language for the interview: Pick One Language for the Coding Interview.

You need to be very comfortable in the language and be knowledgeable.

Read more about choices:

See language resources here

Interview Prep

If you have tons of extra time:

Choose one:

Language Specific

Here are my recommendations by language. I don't have resources for all languages. I welcome additions.

If you read through one of these, you should have all the data structures and algorithms knowledge you'll need to start doing coding problems.

C++

Java

Python

Before you Get Started

1. You Won't Remember it All

I watched hours of videos and took copious notes, and months later there was much I didn't remember. I spent 3 days going through my notes and making flashcards, so I could review.

Please, read so you won't make my mistakes:

Retaining Computer Science Knowledge.

A course recommended to me (haven't taken it): Learning how to Learn.

3. Start doing coding interview questions while you're learning data structures and algorithms

You need to apply what you're learning to solving problems, or you'll forget. I made this mistake. Once you've learned a topic, and feel comfortable with it, like linked lists, open one of the coding interview books and do a couple of questions regarding linked lists. Then move on to the next learning topic. Then later, go back and do another linked list problem, or recursion problem, or whatever. But keep doing problems while you're learning. You're not being hired for knowledge, but how you apply the knowledge. There are several books and sites I recommend. See here for more: Coding Question Practice.

4. Review, review, review

I keep a set of cheat sheets on ASCII, OSI stack, Big-O notations, and more. I study them when I have some spare time.

Take a break from programming problems for a half hour and go through your flashcards.

5. Focus

There are a lot of distractions that can take up valuable time. Focus and concentration are hard. Turn on some music without lyrics and you'll be able to focus pretty well.

The Daily Plan

Some subjects take one day, and some will take multiple days. Some are just learning with nothing to implement.

Each day I take one subject from the list below, watch videos about that subject, and write an implementation in:

  • C - using structs and functions that take a struct * and something else as args
  • Python - using built-in types (to keep practicing Python)
  • and write tests to ensure I'm doing it right, sometimes just using simple assert() statements

Why code in all of these?

  • Practice, practice, practice, until I'm sick of it, and can do it with no problem (some have many edge cases and bookkeeping details to remember)
  • Work within the raw constraints (allocating/freeing memory without help of garbage collection (except Python or Java))
  • Make use of built-in types, so I have experience using the built-in tools for real-world use (not going to write my own linked list implementation in production)

I may not have time to do all of these for every subject, but I'll try.

You can see my code here:

Prerequisite Knowledge

Algorithmic complexity / Big-O / Asymptotic analysis

Data Structures

  • Arrays

    • Implement an automatically resizing vector.
    • Description:
    • Implement a vector (mutable array with automatic resizing):
      • Practice coding using arrays and pointers, and pointer math to jump to an index instead of using indexing.
      • New raw data array with allocated memory
        • can allocate int array under the hood, just not use its features
        • start with 16, or if starting number is greater, use power of 2 - 16, 32, 64, 128
      • size() - number of items
      • capacity() - number of items it can hold
      • is_empty()
      • at(index) - returns item at given index, blows up if index out of bounds
      • push(item)
      • insert(index, item) - inserts item at index, shifts that index's value and trailing elements to the right
      • prepend(item) - can use insert above at index 0
      • pop() - remove from end, return value
      • delete(index) - delete item at index, shifting all trailing elements left
      • remove(item) - looks for value and removes index holding it (even if in multiple places)
      • find(item) - looks for value and returns first index with that value, -1 if not found
      • resize(new_capacity) // private function
        • when you reach capacity, resize to double the size
        • when popping an item, if size is 1/4 of capacity, resize to half
    • Time
      • O(1) to add/remove at end (amortized for allocations for more space), index, or update
      • O(n) to insert/remove elsewhere
    • Space
      • contiguous in memory, so proximity helps performance
      • space needed = (array capacity, which is >= n) * size of item, but even if 2n, still O(n)
  • Linked Lists

    • Description:
    • C Code (video) - not the whole video, just portions about Node struct and memory allocation
    • Linked List vs Arrays:
    • why you should avoid linked lists (video)
    • Gotcha: you need pointer to pointer knowledge: (for when you pass a pointer to a function that may change the address where that pointer points) This page is just to get a grasp on ptr to ptr. I don't recommend this list traversal style. Readability and maintainability suffer due to cleverness.
    • Implement (I did with tail pointer & without):
      • size() - returns number of data elements in list
      • empty() - bool returns true if empty
      • value_at(index) - returns the value of the nth item (starting at 0 for first)
      • push_front(value) - adds an item to the front of the list
      • pop_front() - remove front item and return its value
      • push_back(value) - adds an item at the end
      • pop_back() - removes end item and returns its value
      • front() - get value of front item
      • back() - get value of end item
      • insert(index, value) - insert value at index, so current item at that index is pointed to by new item at index
      • erase(index) - removes node at given index
      • value_n_from_end(n) - returns the value of the node at nth position from the end of the list
      • reverse() - reverses the list
      • remove_value(value) - removes the first item in the list with this value
    • Doubly-linked List
  • Stack

  • Queue

    • Circular buffer/FIFO
    • Implement using linked-list, with tail pointer:
      • enqueue(value) - adds value at position at tail
      • dequeue() - returns value and removes least recently added element (front)
      • empty()
    • Implement using fixed-sized array:
      • enqueue(value) - adds item at end of available storage
      • dequeue() - returns value and removes least recently added element
      • empty()
      • full()
    • Cost:
      • a bad implementation using linked list where you enqueue at head and dequeue at tail would be O(n) because you'd need the next to last element, causing a full traversal each dequeue
      • enqueue: O(1) (amortized, linked list and array [probing])
      • dequeue: O(1) (linked list and array)
      • empty: O(1) (linked list and array)
  • Hash table

More Knowledge

Trees

Sorting

As a summary, here is a visual representation of 15 sorting algorithms. If you need more detail on this subject, see "Sorting" section in Additional Detail on Some Subjects

Graphs

Even More Knowledge

System Design, Scalability, Data Handling

You can expect system design questions if you have 4+ years of experience.


Final Review

This section will have shorter videos that you can watch pretty quickly to review most of the important concepts.
It's nice if you want a refresher often.
  • Series of 2-3 minutes short subject videos (23 videos)
  • Series of 2-5 minutes short subject videos - Michael Sambol (18 videos):
  • [Sedgewick Videos - Algorithms I]
  • [Sedgewick Videos - Algorithms II]

Coding Question Practice

Now that you know all the computer science topics above, it's time to practice answering coding problems.

Coding question practice is not about memorizing answers to programming problems.

Why you need to practice doing programming problems:

  • Problem recognition, and where the right data structures and algorithms fit in
  • Gathering requirements for the problem
  • Talking your way through the problem like you will in the interview
  • Coding on a whiteboard or paper, not a computer
  • Coming up with time and space complexity for your solutions
  • Testing your solutions

There is a great intro for methodical, communicative problem solving in an interview. You'll get this from the programming interview books, too, but I found this outstanding: Algorithm design canvas

Supplemental:

Read and Do Programming Problems (in this order):

Coding exercises/challenges

Once you've learned your brains out, put those brains to work. Take coding challenges every day, as many as you can.

Coding Interview Question Videos:

Challenge repos:

Mock Interviews:

Your Resume

  • See Resume prep items in Cracking The Coding Interview and back of Programming Interviews Exposed
  • Very Important thing to remember while creating your resume, if you applying for big companies is that make it ATS Compliant.
  • How to Create or Check if your Resume is ATS Compliant

Be thinking of for when the interview comes

Think of about 20 interview questions you'll get, along with the lines of the items below. Have 2-3 answers for each. Have a story, not just data, about something you accomplished.

  • Why do you want this job?

  • What's a tough problem you've solved?

  • Biggest challenges faced?

  • Best/worst designs seen?

  • Ideas for improving an existing product

  • How do you work best, as an individual and as part of a team?

  • Which of your skills or experiences would be assets in the role and why?

  • What did you most enjoy at [job x / project y]?

  • What was the biggest challenge you faced at [job x / project y]?

  • What was the hardest bug you faced at [job x / project y]?

  • What did you learn at [job x / project y]?

  • What would you have done better at [job x / project y]?

  • If you find hard to come up with good answers of this type interview questions, you can refer below link for some answer templates and have some idea.

  • General Interview Questions and their Answers

Have questions for the interviewer

Some of mine (I already may know answer to but want their opinion or team perspective):
  • How large is your team?
  • What does your dev cycle look like? Do you do waterfall/sprints/agile?
  • Are rushes to deadlines common? Or is there flexibility?
  • How are decisions made in your team?
  • How many meetings do you have per week?
  • Do you feel your work environment helps you concentrate?
  • What are you working on?
  • What do you like about it?
  • What is the work life like?
  • How is work/life balance?

Additional Books

These are here so you can dive into a topic you find interesting.

Additional Detail on Some Subjects

Video Series

Sit back and enjoy.

Computer Science Courses

Algorithms implementation

Papers

LICENSE

CC-BY-SA-4.0

About

License:Creative Commons Attribution Share Alike 4.0 International