HalmonLui / coding-lessons

Dive deeper and review programming concepts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coding Lessons

Based off of https://github.com/HalmonLui/coding-interview-university. I will be editing and adding to this list throughout my career as a software engineer

Implementations of Data Structures and Algorithms can be found in Jupyter notebooks written for Python 3.

Don't feel you aren't smart enough

Interview Process & General Interview Prep

Python

The Daily Plan

You don't need to memorize the guts of every algorithm.

Write code on a whiteboard or paper, not a computer. Test with some sample inputs. Then test it out on a computer.

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:
    • 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

    • Stacks (video)
    • Will not implement. Implementing with array is trivial
  • Queue

    • Queue (video)
    • 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

Graphs can be used to represent many problems in computer science, so this section is long, like trees and sorting were.

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.

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

No whiteboard at home? That makes sense. I'm a weirdo and have a big whiteboard. Instead of a whiteboard, pick up a large drawing pad from an art store. You can sit on the couch and practice. This is my "sofa whiteboard". I added the pen in the photo for scale. If you use a pen, you'll wish you could erase. Gets messy quick. I use a pencil and eraser.

my sofa whiteboard

Supplemental:

Read and Do Programming Problems (in this order):

See Book List above

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 sites:

Language-learning sites, with challenges:

Challenge repos:

Mock Interviews:

Once you're closer to the interview

Your Resume

  • See Resume prep items in Cracking The Coding Interview and back of Programming Interviews Exposed

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]?

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?

Once You've Got The Job

Congratulations!

Keep learning.

You're never really done.


*****************************************************************************************************
*****************************************************************************************************

Everything below this point is optional.
By studying these, you'll get greater exposure to more CS concepts, and will be better prepared for
any software engineering job. You'll be a much more well-rounded software engineer.

*****************************************************************************************************
*****************************************************************************************************

Additional Books

These are here so you can dive into a topic you find interesting.
  • The Unix Programming Environment

    • An oldie but a goodie
  • The Linux Command Line: A Complete Introduction

    • A modern option
  • TCP/IP Illustrated Series

  • Head First Design Patterns

    • A gentle introduction to design patterns
  • Design Patterns: Elements of Reusable Object-Oriente​d Software

    • AKA the "Gang Of Four" book, or GOF
    • The canonical design patterns book
  • UNIX and Linux System Administration Handbook, 5th Edition

  • Algorithm Design Manual (Skiena)

    • As a review and problem recognition
    • The algorithm catalog portion is well beyond the scope of difficulty you'll get in an interview
    • This book has 2 parts:
      • Class textbook on data structures and algorithms
        • Pros:
          • Is a good review as any algorithms textbook would be
          • Nice stories from his experiences solving problems in industry and academia
          • Code examples in C
        • Cons:
          • Can be as dense or impenetrable as CLRS, and in some cases, CLRS may be a better alternative for some subjects
          • Chapters 7, 8, 9 can be painful to try to follow, as some items are not explained well or require more brain than I have
          • Don't get me wrong: I like Skiena, his teaching style, and mannerisms, but I may not be Stony Brook material
      • Algorithm catalog:
        • This is the real reason you buy this book
        • About to get to this part. Will update here once I've made my way through it
    • Can rent it on kindle
    • Answers:
    • Errata
  • Write Great Code: Volume 1: Understanding the Machine

    • The book was published in 2004, and is somewhat outdated, but it's a terrific resource for understanding a computer in brief
    • The author invented HLA, so take mentions and examples in HLA with a grain of salt. Not widely used, but decent examples of what assembly looks like
    • These chapters are worth the read to give you a nice foundation:
      • Chapter 2 - Numeric Representation
      • Chapter 3 - Binary Arithmetic and Bit Operations
      • Chapter 4 - Floating-Point Representation
      • Chapter 5 - Character Representation
      • Chapter 6 - Memory Organization and Access
      • Chapter 7 - Composite Data Types and Memory Objects
      • Chapter 9 - CPU Architecture
      • Chapter 10 - Instruction Set Architecture
      • Chapter 11 - Memory Architecture and Organization
  • Introduction to Algorithms

    • Important: Reading this book will only have limited value. This book is a great review of algorithms and data structures, but won't teach you how to write good code. You have to be able to code a decent solution efficiently
    • AKA CLR, sometimes CLRS, because Stein was late to the game
  • Computer Architecture, Sixth Edition: A Quantitative Approach

    • For a richer, more up-to-date (2017), but longer treatment
  • Programming Pearls

    • The first couple of chapters present clever solutions to programming problems (some very old using data tape) but that is just an intro. This a guidebook on program design and architecture

Additional Learning

I added them to help you become a well-rounded software engineer, and to be aware of certain
technologies and algorithms, so you'll have a bigger toolbox.

About

Dive deeper and review programming concepts

License:MIT License


Languages

Language:Jupyter Notebook 100.0%