# 107+ Coding Interview Problems with Detailed Solutions

## Motivation

I am building a database of most frequently appeared coding interview problems that I think are the most valuable and productive to spend time on. For each one, I am including my thoughts of process on how to approach and solve it, adding well-documented solutions with test cases, time and space complexity analysis. My goal is to help you get good algorithms and data structures so that you can prepare better for your next coding interviews.

These resources that I am looking at are:

- Interview Cake
- LeetCode
- Cracking the Coding Interviews
- Grokking the Coding Interview: Patterns for Coding Questions
- Elements of Programming Interviews

## Table of Contents

**Interview Cake**- Array and string manipulation
- Merge meeting times
- Reverse string in place
- Reverse words
- Merge sorted arrays
- Single riffle shuffle

- Hashing and hash tables
- In-flight entertainment
- Permutation palindrome
- Word cloud data
- Top scores
- Find duplicate files

- Greedy algorithms
- Sorting, searching, and logarithms
- Find rotation point
- Find repeat

- Trees and graphs
- Dynamic programming and recursion
- Queues and stacks
- Linked lists
- General programming
- Rectangular love
- Temperature tracker

- Bit manipulation
- Combinatorics, probability, and other math
- Which appears twice
- Find in ordered set
- Simulate 5-sided die
- Simulate 7-sided die
- Two egg problem

*TODO: System Design*

- Array and string manipulation
**Practical Algorithms and Data Structures****LeetCode**- Array/String
- Two sum I
- Two sum II
- Valid palindrome
- Implement strstr()
- Reverse words in string
- String to integer
- Valid number
- Longest substring without repeating characters
*TODO: read more about sliding windows problem here*

- Missing ranges
- One edit distance
- Read n characters given Read4

- Math
- Linked list
- Merge sorted linked list
- Add two numbers
- Swap nodes in pairs
- Merge k sorted linked list
- Copy list with random pointer

- Binary tree
- Validate binary search tree
- Maximum depth of binary tree
- Minimum depth of binary tree
- Balanced binary tree
- Convert sorted array to balanced binary search tree
- Convert sorted linked list to balanced binary search tree
- Binary tree maximum path sum
- Binary tree upside down

- Bit manipulation
- Misc
- Spiral matrix
- Integer to roman
- Roman to integer
- Clone graph

- Stack
- Min stack
- Evaluate reverse polish notation
- Valid parenthesis

- Dynamic programming
- Climbing stairs
- Unique paths
- Maximum sum subarray
- Maximum product max array
- Coins in a line

- Binary search
- Search insert position
- Find minimum in sorted rotated array

- Array/String
**Cracking the Coding Interviews**- Bit manipulation

**Elements of Programming Interviews****Grokking the Coding Interview: Patterns for Coding Questions**- Sliding Window
- Average of any contiguous subarray of size k
- Maximum sum of any contiguous subarray of size k
- Smallest subarray with a given sum
- Longest substring with k distinct characters
- Fruits into baskets
- Longest substring without repeating characters
- Longest substring after k replacements
- Longest substring after ones replacements
- Permutation in string
- String anagrams
- Smallest window containing substring
- Words concatenation

- Two pointers
- Pair with target sum
- Remove duplicates
- Squaring a sorted array
- Triplet sum to zero
- Triplet sum close to target
- Triplet with smaller sum
- Subarray with product less than a target
- Dutch national flag problem

- Fast and slow pointers
- Merge intervals
- Cyclic sort
- In-place reversal of a linked list
- Tree breath first search
- Tree depth first search

- Sliding Window
**Other**- Data structures
- Linked List
- Queue
- Stack
- Tree
- Graph
- Trie
- Heap
- Priority Queue
- Bloom filter
- LRU cache

- Sorting

- Data structures

## Developing

Count the number of questions:

```
make count
```

Clean up, lint source files, run tests and be ready for a push:

```
make ready
```

Test only:

```
make test
```

Test and report:

```
make cover
```

Test verbose:

```
make test-verbose
```

Lint:

```
make lint
```

Clean up:

```
make clean
```

For more information:

```
make help
```

## References

- Sorting algorithm cheat sheet
- LeetCode patterns
- LeetCode's 50 common interview questions
- Practical Algorithms and Data Structures