Skip to content
A personal log of learning and solving problems
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images word break - white board pic Oct 1, 2016
mylib clean up; add notes Aug 27, 2016
Data-Structure-Algorithms-Concepts-Notes.md github markdown changes and additonal notes Aug 4, 2018
Design-and-implement-LRU.py Add 🎶 May 10, 2016
Design-patterns.md
Histogram.py
README.md
alarm-clock.py command line alarm clock 👍 Nov 10, 2015
binary-search-tree-LCA.py
binary-search-tree-check.py
binary-search-tree-closest-value.py major rewrite;simplify code 👍 Aug 7, 2016
binary-search-tree-create-sorted-input.py Create BST from sorted list 🎶 Feb 29, 2016
binary-search-tree-create.py Convert list to BST Sep 7, 2015
binary-search-tree-delete-node.py update BST Library Jul 10, 2016
binary-search-tree-find-index-i-equals-value.py
binary-search-tree-find-value.py -Add iterative solution Aug 7, 2016
binary-search-tree-first-last-occurance.py Rewrite; clean, easy to follow with 🎶 Jul 12, 2016
binary-search-tree-first-value-greater-than-K.py Major rewrite;optimize code 👍 Aug 7, 2016
binary-search-tree-fully-balanced.py fully balanced BST Jul 10, 2016
binary-search-tree-input-variations.py Modify logic; easy to follow along Sep 8, 2016
binary-search-tree-largestK.py add solution #2 - simplified Aug 6, 2018
binary-search-tree-max-value.py find max value of BST Sep 7, 2015
binary-search-tree-min-value.py find min value of BST Sep 7, 2015
binary-search-tree-minimal-height.py
binary-search-tree-next-iterator.py
binary-search-tree-range.py Find # nodes that lie in the given range of BST Sep 12, 2015
binary-search-tree-search-sorted-rotated-list.py Add comments Apr 27, 2016
binary-search-tree-smallestK.py Include observation 🎶 Sep 13, 2015
binary-search-tree-squareroot.py Find the square root of an integer without using square root function May 19, 2016
binary-tree-ancestor.py correct 🎶 Jul 9, 2016
binary-tree-balanced.py update example Sep 6, 2018
binary-tree-check-if-path-exists.py simplify algorithm Sep 6, 2015
binary-tree-check-symmetric.py add diagram of tree Nov 29, 2016
binary-tree-clone.py
binary-tree-construct.py major rewrite, add diagram Nov 29, 2016
binary-tree-count-path-sum-with-path.py
binary-tree-count-path-sum.py find path variations based on target value 💡 👍 Oct 17, 2015
binary-tree-deepest-node.py rewrite algorithm Sep 13, 2015
binary-tree-edge-nodes.py add variations;same results Dec 3, 2015
binary-tree-find-level-with-max-pathsum.py simplify alogorithm Sep 6, 2015
binary-tree-first-common-ancestor-of-two-nodes-traverse-up.py Logic to fina LCA when you can only traverse up 💡 Nov 17, 2015
binary-tree-first-common-ancestor-of-two-nodes.py Add observation 🎶 Jul 10, 2016
binary-tree-flip.py Add diagram Oct 18, 2016
binary-tree-height.py clean up;add 🎶;add pic of tree Nov 11, 2016
binary-tree-invert.py Add DP and Binary tree questions Jun 2, 2016
binary-tree-leaves-nodes.py
binary-tree-max-bst-size.py
binary-tree-max-diameter-height.py add diagram, 🎶,clean up code 👍 Nov 24, 2016
binary-tree-max-value.py add variation;same result Dec 3, 2015
binary-tree-next-right.py
binary-tree-node-depth-path.py add question and solution to find node depth and path. Can be further… Oct 6, 2015
binary-tree-preorder-to-postorder.py Finf postorder given preorder Dec 6, 2015
binary-tree-root-to-leaf-paths-recursive.py
binary-tree-root-to-leaf-paths.py
binary-tree-shortest-path.py
binary-tree-shortest-path2.py rename function Oct 8, 2015
binary-tree-size.py add note Sep 1, 2015
binary-tree-structurally-identical.py
binary-tree-subset.py find binary tree subset 💡 🎶 👍 Oct 13, 2015
binary-tree-sum-of-all-root-to-leaf-paths.py sum of all path in binary tree 👍 Sep 15, 2015
binary-tree-traversal-in-order.py clean up; add visuals Nov 13, 2016
binary-tree-traversal-leaf-sum.py markup changes Aug 28, 2016
binary-tree-traversal-left-leaf-sum.py clean up Oct 18, 2016
binary-tree-traversal-level-order-each-line.py simplify logic 🚀 Jul 30, 2018
binary-tree-traversal-level-order.py
binary-tree-traversal-post-order.py modify algorithm to easily follow 🚀 Sep 23, 2018
binary-tree-traversal-pre-order.py
binary-tree-traversal-spiral-order.py add traversal question Aug 28, 2016
bit-count-1s.py
bit-lonely-integer.py find lonely integer using bit operation Apr 21, 2016
bit-operation-add.py
bit-operation-check-if-number-is-power-of-2.py more questions Jun 3, 2015
bit-operation-multiply-number-by-power-of-2.py more questions Jun 3, 2015
bit-operation-subtract.py more questions Jun 3, 2015
bitwise-operations.py
bloom-filter.py
boggle.py additional challenging questions Jun 8, 2015
bst-check-if-value-exists.py Add 🎶 Sep 4, 2016
bst-delete-nodes-outside-range.py Delete notes outside range in BST Sep 10, 2016
celsius-fahrenheit.py more questions Jun 7, 2015
check-if-linkedlist-is-a-palindrome.py Add new question to check if a linked list is a palindrome Jul 30, 2015
check-if-strings-are-isomorphic.py check if strings are isomorphic Dec 2, 2015
closest-matching-pair.py Find closest matching pair May 14, 2015
cmd-line-echo.py command line echo Dec 8, 2015
coin-change-with-lookup.py Fix issues;add notes 🎶 thumbsup: Dec 3, 2015
coin-change.py
complete-binary-tree-count-nodes.py find nodes in a complete binary tree Oct 27, 2016
construct-binary-tree-from-preorderX.py clean up;easy to follow Nov 15, 2016
convert-list-to-heap.py
count-inversions.py Count inversions in an array Aug 16, 2015
count-perfect-squares.py Count perfect squares Apr 11, 2016
create-word-from-dictionary.py Can you create the given word from the dictionary? Nov 27, 2015
dequeue-moving-window.py -optimize sliding window problem 💥 May 4, 2016
design-data-structure-constant-time.py reorganize and add reference Aug 17, 2016
dictionary-intro.py add info about dictionaries, sort and list comprehensions Aug 23, 2015
double-linkedlist-intro.py add double linked list intro Mar 13, 2016
dp-all-balanced-partition.py
dp-balanced-parentheses.py Major rewrite;easy to scan and follow 👍 Sep 10, 2016
dp-balanced-partition.py fix path Aug 8, 2016
dp-cake-thief.py solve cake thief problem posted by Interview Cake Oct 24, 2016
dp-check-balanced-partition.py check balanced partition Jun 7, 2016
dp-coin-play.py update logic; easy to follow Sep 21, 2016
dp-count-stair-combinations.py Major rewrite;clean up 👍 Nov 19, 2016
dp-egg-drop-2eggs.py
dp-egg-drop.py major rewrite, easy to follow Sep 28, 2016
dp-find-all-longest-increasing-subsequence.py find all LIS (TODO) May 31, 2016
dp-find-all-stair-combinations.py using yield 👍 Nov 21, 2016
dp-knight-chess-movement.py solve DP problem! 💥 Mar 20, 2016
dp-largest-sum-sublist-modulo.py fix typo Oct 1, 2016
dp-largest-sum-sublist.py Update 🎶 Oct 23, 2016
dp-longest-increasing-subsequence.py najor rewrite;easy to follow code Aug 3, 2016
dp-matrix-multiplication.py Add notes; clean up; easy to follow Jul 19, 2016
dp-matrix-path.py DP solution to find #path in a binary matrix from top left to bottom … Jul 19, 2016
dp-maxsize-square-submatrix.py
dp-minimum-coins.py yield;major rewrite; thumbsup: Nov 23, 2016
dp-multiply-using-addition-subtraction.py Multiply without using * and / Jul 24, 2016
dp-power-set.py simplify code 👍 Aug 31, 2016
dp-string-combinations.py
dp-string-distance.py add notes;modify code Jun 1, 2016
dp-string-permutation.py add 🎶 Aug 19, 2018
dp-target-permutations.py modify comment Sep 23, 2018
dp-text-justification.py Add more problems to solve Jul 2, 2016
dp-word-wrap.py Add comments and cleanup Jul 4, 2016
elevator.py Design elevator using OO principles Dec 9, 2015
expression-evaluator.py expression evaluator Oct 28, 2016
factorial-trailingzero.py
factorial.py Questions from queue, stack and factorial; updated TOC Jun 7, 2015
fibonacci-find-even-odd.py
fibonacci-find-nth-lookup.py nth Fibonacci number using lookup Jan 29, 2016
fibonacci-find-nth.py
fibonacci.py Update solutions and TOC Aug 29, 2015
find-conflicting-appointments.py find conflicting appointments May 31, 2015
find-distinct-elements-in-lists.py
find-greatest-common-divisor.py
find-integer-pairs-equal-to-sum.py Update solutions and TOC Aug 29, 2015
find-integers-that-match-expression.py find triplets in the list that add up to the given sum 💥 Dec 10, 2015
find-intersection-of-sorted-lists.py Update solutions and TOC Aug 29, 2015
find-ip-address-variations.py more questions Jun 7, 2015
find-k-maximum.py Modify to show variuous options;improve time complexity Jul 4, 2015
find-maximum-gain-multiple.py solve max gain from selling stock multiple times Oct 16, 2016
find-maximum-gain.py
find-median-of-two-sorted-lists.py major rewrite;add 🎶;easy to follow Oct 25, 2016
find-median-sorted-list.py find median of a sorted list Sep 23, 2015
find-median-unsorted-list.py solve problem using quick select Apr 25, 2016
find-missing-and-duplicate-number.py find the duplication number Dec 12, 2015
find-nth-node-from-the-end-in-a-single-linked-list.py
find-square-root-without-using-sqrt-function.py
find-three-numbers-that-add-to-a-given-input.py optimized code and works! 👍 Nov 26, 2015
find-three-numbers-when-multipled-provide-max-value.py
find-top-3-bottom-3-values-in-a-list.py Find top 3 and bottom 2 values from the list in O(n) Jan 9, 2016
find-word-combinations.py
first-occurance-of-substring.py more questions Jun 7, 2015
flatten-hash.py Add Notes Dec 2, 2015
format-integer.py
generate-rand7.py update question Sep 25, 2016
graph-check-if-path-exists.py Solve problem, if path exists in a graph between two nodes 👍 Oct 9, 2015
graph-dag-introduction.py Add reference May 21, 2016
graph-detect-cycle-topological-sort.py Modify Topological Sort to detect cycles 🎶 May 11, 2016
graph-detect-cycles-DFS.py Modify DFS to detect cycles 🎶 May 11, 2016
graph-find-islands.py Add references Sep 5, 2018
graph-longest-path.py Solve longest path in a Directed Acyclic Graph from a source vertex May 27, 2016
graph-strongly-connected-components.py
graph-topological-sort-alien-dictionary.py Topological sort May 24, 2016
graph-topological-sort-kahn.py Add time complexity Aug 3, 2016
graph-topological-sort.py Topological sort 💡 Sep 30, 2015
graph-transform-word.py add comments 🎶 Sep 23, 2018
graph-traversal-bfs.py clean up;simplify Aug 24, 2018
graph-traversal-dfs.py
happy-number.py find happy number Nov 29, 2016
heap-valid.py add: valid complete binary tree Aug 12, 2018
heapq-library.py Update TOC;heapq info Jun 8, 2015
heaps-introduction.py fix typo;add comment 😌 Sep 13, 2015
heapsort-take2.py simplify;clean up;easy to follow along Aug 1, 2016
heapsort.py simplify;clean up;easy to follow along Aug 1, 2016
implement-queue-using-two-stacks.py
inc-dec-max-min.py design DS to inc,dec,max,min in O(1) 🎶 🚀 Nov 10, 2016
insert-delete-getrandom.py
interval-scheduler.py Update solutions and TOC Aug 29, 2015
k-largest-element.py add questions, organize Aug 29, 2015
lambda.py Additional problems to practice 😄 🤘 Sep 23, 2015
largest-rectangle-in-a-binary-matrix.py find area of largest rectangle in a binary matrix Jul 17, 2016
linked-list-cycle-insert.py add solution #2 May 16, 2016
linked-list-cycle.py fix path Aug 21, 2016
linked-list-delete-node.py Major rewrite; simplify; handle 2 different use cases - return and no… Oct 29, 2016
linked-list-introduction.py Linked List introduction Sep 15, 2015
linked-list-max-queue.py findMax() in a linked list May 18, 2016
linked-list-merge-duplicates.py solve linked list intersection Oct 16, 2016
linked-list-middle-element.py update logic for finding middle node in a linked list Aug 18, 2016
linked-list-remove-duplicates.py Remove duplicate values & retain order in linked list May 14, 2016
linked-list-reverse.py rewrite recursive; easy to follow 👍 Aug 8, 2016
linked-list-split.py
linked-list-swap-adjacent-nodes.py add linked list question Jun 27, 2016
linked-list-zip.py simplify splitInMiddle(node) 🚀 Jul 29, 2018
list-add-two-numbers.py add numbers in list Sep 23, 2015
list-alternate-positive-negative.py print alternate positive and negative values Apr 10, 2016
list-find-consecutive-negative-values-target.py Given unsorted list of positive and negative values check if there ar… May 18, 2016
list-find-consecutive-positive-values-target.py Given unsorted list of positive values check if there are consecutive… May 18, 2016
list-find-pivot-balanced.py
list-find-product-no-division.py rewrite; simplify code 👍 Oct 16, 2016
list-find-shortest-distance.py major rewrite;easy to follow logic Aug 19, 2016
list-find-subset-sumzero.py
list-popular-element-sorted.py Find popular value in a sorted list 💡 Apr 5, 2016
list-popular-element-unsorted.py
lists-swap-same-sum.py add question to solve Dec 13, 2015
longest-common-subsequence-find-all.py regor;small problems easy to follow 🚀 Nov 22, 2015
longest-common-subsequence-find-one.py regor;small problems easy to follow 🚀 Nov 22, 2015
longest-common-subsequence-length.py
longest-common-subsequence.py
longest-common-substring-length.py Optimize solution to use less space and include observation 🎶 Jun 19, 2016
longest-common-substring.py
longest-file-path.py Longest file path Nov 4, 2016
longest-subset-of-string-with-two-characters.py
matrix-count-rectangles.py count rectangles in a matrix Jul 21, 2016
matrix-spiral-print.py Major rewrite; expanded notes Sep 13, 2016
merge-overlapping-intervals.py optimize & notes 👍 Apr 7, 2016
merge-sorted-list.py Merge sorted list Feb 14, 2016
min-value-two-unsorted-lists.py simplify code 💥 Jan 7, 2016
minimum-window-matching-pattern.py add: find characters in the pattern Jun 27, 2015
nearest-point.py additional challenging questions Jun 8, 2015
number-factors.py Find all possible numbers which multiply to a give number Apr 14, 2016
palindrome.py new challenge - check if string is palindrome May 29, 2015
people-tree.py
phone-number-mnemonics.py more questions Jun 7, 2015
power.py bit operation to compute n^k Feb 21, 2016
prefix-tree.py
prime.py
python-intro.py swap values using temporary space + dis module 💡 Nov 14, 2015
python-intro2.py Add 🎶 about string split Sep 4, 2016
python-intro3.py add alternate solution to sort by multiple keys Aug 21, 2016
queue-implement-max.py add findMax() given a list May 18, 2016
queue-implement.py
queue-implementation-using-dynamic-array.py Questions from queue, stack and factorial; updated TOC Jun 7, 2015
queue-implementation-using-fixed-sized-array.py Questions from queue, stack and factorial; updated TOC Jun 7, 2015
queue-implementation-using-linked-lists.py add notes May 7, 2016
randomize-array-elements.py additional challenging questions Jun 8, 2015
rate-limiting-webservice.py Design rate limiting webservice 💥 Dec 5, 2015
requirements.txt Add requirements.txt Oct 20, 2015
reverse-integer.py reorganize questions; reverse an integer recursively Apr 6, 2016
reverse-linked-list.py reverse a linked list Jul 31, 2015
reverse-sentance.py major rewrite; optimal solution Oct 18, 2016
reverse-string-recursiverly.py
rotate-array.py Update solutions and TOC Aug 29, 2015
rotate-list-minimum.py
rotate-matrix-anti-clockwise.py rotate maatrix anti clockwise Aug 13, 2016
say-as-you-see.py
search-find-unique-in-duplicates.py add algorithm to find a unique value in duplicates Aug 14, 2016
search-missing-value.py find missing value in an increasing sequence Aug 25, 2016
sort-array-containing-zeros-ones-twos.py
sort-bucket-sort.py Add bucket sort Feb 14, 2016
sort-bucketsort-string.py solve using bucket sort Sep 16, 2016
sort-by-word-frequency.py
sort-heap-mergeK-lists.py merge K sorted lists of size N using heap sort 💡 Aug 16, 2016
sort-insertion-sort.py Add 🎶 about time complexity Sep 9, 2016
sort-merge-sort.py update 🎶 Sep 6, 2016
sort-merge.py merge two sorted lists Nov 12, 2015
sort-quick-select.py Quick Select algorithm Feb 14, 2016
sort-quicksort.py Add 🎶 about time complexity Sep 9, 2016
sort-radix-sort.py
sort-running-median.py find running median Aug 11, 2016
sort-stack-in-descending-order.py working solution to sort stack in descending order Aug 14, 2015
sort-version-numbers.py edits to work on python3 Nov 25, 2015
sorted-list-fix.py Can you fix an almost sorted list with one swap Jun 21, 2016
sorted-list-remove-duplicates.py modify logic 🚀 Sep 23, 2018
stack-calculator.py stack calculator Dec 22, 2015
stack-check-matching-parenthesis-square-brackets-and-curly-brackets.py
stack-check-matching-parenthesis.py
stack-implement.py
stack-implementation-using-dynamic-array.py Questions from queue, stack and factorial; updated TOC Jun 7, 2015
stack-implementation-using-fixed-sized-array.py Questions from queue, stack and factorial; updated TOC Jun 7, 2015
stack-implementation-using-linked-lists.py Questions from queue, stack and factorial; updated TOC Jun 7, 2015
stack-longest-matching-parenthesis.py
stack-with-maxvalue.py
string-Kmost-distinct-substring.py solve length of substring with Kmost distinct characters Oct 16, 2016
string-anagram.py find anagrams Sep 15, 2016
string-combinations-by-placing-spaces.py
string-combinations-length-k.py Add find string combinations of length k Dec 1, 2015
string-combinations.py
string-count-distinct-substrings.py Find #distinct substrings Apr 2, 2016
string-longest-increasing-substring.py optimize code 👍 Aug 30, 2016
string-longest-palindrome-substring.py add observation 💡 Aug 20, 2016
string-longest-substring-unique-character.py
string-next-palindrome.py fix typo Aug 6, 2016
string-numeronym.py Generate all Numeronyms for a string Jun 11, 2016
string-pattern-turns.py Add observation May 10, 2016
string-permutations.py add comment Jun 19, 2015
string-search-KMP.py Add brut force + notes Sep 17, 2016
string-search-suffix-array.py Add 🎶 and observations Aug 30, 2016
string-search.py Add KMP - string search algorithm Mar 27, 2016
string-split-text-message.py split text message Jan 18, 2016
string-words.py add question Nov 7, 2015
strings-find-all-substrings.py
sum-of-numbers.py update question Jul 17, 2015
swap-two-variable-values-without-additional-space.py
t9.py additional challenging questions Jun 8, 2015
time-availability.py add questions;find time availability Aug 5, 2016
two-dimensional-array-number-exist.py
unix-diff.py implement unix diff Jul 15, 2015
validate-sudoku.py major rewrite;fix logic 👍 Nov 14, 2016
weighted-random-numbers.py weighted random numbers Nov 17, 2016
word-break.py fix example;add comment Aug 25, 2018

README.md

Cracking the coding interview

Collection of interesting questions and solutions that involve data structures, algorithms and concepts. Solutions are in Python version 3.4.3

Table of Contents

Quick References

  1. Command Line Tools
  2. AWK
  3. Python3 👍
  4. MySQL
  5. JavaScript

Data Structures, Algorithms & Concepts

  1. Data structures, algorithms, time complexity and concepts 👍 🎶
  2. Introduction to Concurrency 👍 🎶
  3. Introduction to Design Pattern 🎶
  4. Introduction to Bit Manipulation 💥 🎶
  5. Fun with Bits & Bytes 🚀
  6. Fun with Permuation and Combination 💥 🎶

Brain Teasers (Basic)

  1. Convert celsius to fahrenheit
  2. Find sum of all even numbers for a given range
  3. Find factorial of n
  4. Find square root of a number
  5. Find square root without using sqrt function
  6. Find power of a number
  7. Fibonacci series
    7.1 Find the Fibonacci numbers between the given range
    7.2 Find odd numbers in the Fibonacci series for a given range
  8. Write an "echo" program
  9. Number of perfect squares between two given numbers
  10. Find all possible numbers which multiply to a give number
  11. Can you fix an almost sorted list with one swap (such that the result is sorted)? 🎶

Brain Teasers (Moderate)

  1. Check if a given number is prime
  2. How many trailing zeros are in n! (n factorial) 📝
  3. Reverse an integer
  4. Find the Greatest Common Divisior (GCD) of two positive integers
  5. Validate Sudoku 🎨
  6. Flatten an object representation. Example {a:1, b:2, c:{d:3}} flattens to {a:1,b:2,c.d:3} 💥 👍
  7. Matrix
    7.1 Print the matrix from outside to inside (Spiral) 💥
    7.2 Given a two dimentional matrix where values are increasing. Search for a target value 👍 🎶
    7.3 Rotate a 2D matrix clockwise 90 degrees
    7.4 Rotate a 2D matrix anti-clockwise 90 degrees 👍
  8. Number of perfect squares between two given numbers
  9. Find the coordinates of the rectangle in the 2 dimensional list [TODO]
  10. Check if a number is a happy number
  11. Given an integer and returns all possible combinations of its factors
  12. Given a digit string (from phone keypad), return all possible letter combinations that the number could represent

Permutations and Combinations

  1. References
    1. Introduction to Permutation and Combination 💥 👍
    2. Power set, Permutation, Combination 🚀
  2. Compute all permutations of a string
  3. Find all possible combinations for a given string
  4. Compute all possible string combinations that can be made my placing spaces (zero or one) between them
  5. Given a string containing only digits, restore it by returning all possible valid IP address combinations
  6. Given a phone number provide possible letter mnemonics
  7. Can you create the given word from the dictionary? 👍
  8. Given a set of characters and a positive integer k, print all possible strings of length k that can be formed 👍
  9. Given a word and a dictionary. Find all possible words can you make that are found in the dictionary?
  10. Given a string and pattern with 1's and 0's find the minimum # of turn needed to make sure the pattern does not appear in the string 👍

Bitwise Operations

  1. Introduction to bitwise operations
  2. Bitwise addition
  3. Bitwise subtraction
  4. Given a number n, check whether the number is a power of 2
  5. Given a number n, multiple the number by 2^k
  6. Compute n^k using bit operations 💥 👍
  7. Swap two variable values without additional space
  8. Write an efficient program to unset the right most bit and count number of 1s in binary representation of an integer
  9. Given a list of repeating integers find the lonely integer
  10. Generate rand7 using rand5 💡

Sort

  1. Sorting Algorithms & Notes
    1.1 Quick Sort 👍
    1.2 Quick Selection Sort 🚀
    1.3 Merge Sort
    1.4 Heap Sort 🚀 💥
    1.5 Insertion Sort
    1.6 Bucket Sort
    1.7 Radix Sort
  2. Sort lists,lists of lists and list of dictionaries
  3. Sort a list of ones, twos and threes
  4. Given two sorted list merge them
  5. Merge sorted lists
  6. Sort version numbers 📝 💥
  7. Median
    7.1 Find median of a sorted list
    7.2 Find median of two sorted list 💡 👍 🚀
    7.3 Find median of unsorted list 💡 🎶
    7.4 Find median in a stream of integers (running median) 🚀 🎶 🎨
  8. Unsorted list of values
    8.1 Find the smallest K
    8.2 Find the largest K
  9. Merge K sorted list of size N 🎨 💡
  10. Sort a string
  11. Find the first and second largest value in an unsorted list
  12. Given a sequence of words, print all anagrams together 💡
  13. Sort a string of printable characters 🚀

Search

  1. Implement skip list
  2. Implement Trie - insert, search, searchWith, delete (Prefix Tree) 🎶 💡
  3. Implement Bloom Filter 💡 💥
  4. Implement Suffix Array 🎶 💡
  5. Search using Regular Expression
  6. KMP (Knuth Morris Pratt) algorithm 💥 🚀
  7. Implement Z algorithm
  8. Find the missing number in an increasing sequence (1 ...N) 💡
  9. Given a list of integers with duplicates (can be more than one) find any integer than appears more than once
    9.1 Can modify the input list
    9.2 Cannot modify the input list
  10. Given unsorted values with several duplicates and one value that occurs once find the value TODO
  11. Find duplicates given 2 sorted lists
    11.1 both list of same size
    11.2 one list is >> other
  12. Given a two dimentional matrix where values are increasing. Search for a target value 👍 🎶
  13. Given a sorted list find if a value exists 💥

Lists & Dictionaries

  1. Randomize list elements
  2. Given two numbers as list add them and return result as list
  3. Say as you see - given an input string of integers print the output 📝
  4. Given a list of numbers, return a list of products of all other numbers without using division in O(n) time 💡 🎶
  5. Design a dictionary that performs insert, lookup and delete in constant time O(1)
  6. Find the majority element 💥
    6.1 From unsorted list in linear time and constant storage 👍
    6.2 From sorted list in logrithmic time and constant storage 👍 💡
  7. Two lists
    7.1 Find the intersection of two sorted lists 📝
    7.2 Given two lists, find a pair of values (one from each array) such that you can swap so that both arrays sum to the same value [TODO]
    7.3 Given two sorted list merge them
    7.4 Merge sorted lists
    7.5 Find min value of two unsorted lists 💡 👍
  8. Duplicates
    8.1 Given a list of integers return a list of integers that only occurred once 💡 📝
    8.2 Given a sorted list, remove the duplicates in place, return modified list and #unique values 🎶
  9. Given a list and condition
    9.1 Find all possible 2 numbers in the list that add up to the given sum
    9.2 Find all possible triplets in the list that add up to the given sum
    9.3 Find all possible triplets in the list that satisfies a^2 + b^2 = c^2 🎶 💥
    9.4 There are numbers from 1 to N in an array. One of the number gets duplicated and one is missing. Find out the duplicate number 🎶 [TODO]
    9.5 Given two arrays of integers, find a pair of values (one from each array) you can swap so that both arrays sum to the same value [TODO]
    9.6 Find three numbers when multipled provide max value from the given input
    9.7 Find all possible quadruplets in the list that add up to the given sum
  10. Subarray and condition
    10.1 Find a continuous subarray of sum zero 🎶 🚀
    10.2 Find a continuous subarray of sum target given positive values 🎶
    10.3 Find a continuous subarray of sum target given positive and negative values 🎶 🚀
    10.4 Print alternate positive and negative values while retaining order 💥
    10.5 Find pairs in an integer whose sum is equal to a given value
    10.6 Given a list of integers and two target values find the shortest distance between the two target values 💥 🎶
    10.7 Find the pivot value that splits the list into balanced partitions 🎶 💡
    10.8 Find the maximum subarray sum - Kadane Algorithm 🎶 💡
    10.9 Find #occurrences of the largest sum contiguous subarray of modulo K 🎨 💡
    10.10 Given a list and a number K, print the maximum sum subarray of size K
  11. Rotated list
    11.1 Rotate a list to the right or left by n places
    11.2 Find minimum in a rotated sorted list #RotationPoint 👍 🍰
    11.3 Search a target number in a rotated sorted list 💡
  12. Time intervals
    12.1 Merge overlapping time intervals 🎶
    12.2 Find #conflicting appointments 📝
    12.3 Find conflicting appointments
    12.4 Find the next earliest availability given availability and meeting duration 🚀 🎶
  13. Design 💡
    13.1 Design a data structure that implements insert, remove, contains and get random in O(1) time 💡 🚀 👍
    13.2 Design a data structure that implements increment, decrement, max and min in constant time 🎨 🎶 🚀
    13.3 Implement a function that inserts, deletes and getrandom in O(1) time 🎶 💡
    13.4 Write a function that returns values randomly, according to their weight 💡 🎶

Strings

  1. Find #words in a sentance
  2. Find most and least frequently used words in a sentance
  3. Write a function which finds a closest pair of equal entries 📝
  4. Write a function that given an integer returns a formatted number string 📝 💡 👍
  5. Given a string for a text message and character limit. Break the message without breaking the words and include message count 🎶
  6. Properties
    6.1 Given two strings find if they are Anagrams
    An Anagram is a rearrangement of the letters of one word or phrase to form another word or phrase
    6.2 Check if two given strings are Isomorphic
    Two strings str1 and str2 are called isomorphic if there is a one to one mapping possible for every character of str1 to every character of str2. And all occurrences of every character in ‘str1′ map to same character in ‘str2′
    6.3 Generate all Numeronyms for a given string
    A numeronym is a number-based word. Letters between the first and last are replaced with a number representing the number of letters omitted, such as "i18n" for "internationalization"
  7. Reverse
    7.1 Reverse an integer 👍
    7.2 Reverse a string recursively
    7.3 Reverse all words in a sentance
  8. Palindrome
    8.1 Test if a string is a Palindrome. Ignore all non-alphanumeric characters
    8.2 Given a number find the next largest Palindrome 💡 🎶
    8.3 Find the longest palindromic substring - Manacher's algorithm 💡 🎶 🚀
  9. Substring (A substring is a prefix or suffix of any string. There are n^2 substrings.)
    9.1 Find the number of distinct substrings of a given string 💡
    9.2 Generate all the substrings of a string
    9.3 Find first occurance of substring
    9.4 Find the longest repeating substring (longest substring of a string that occurs at least twice) 💥 💡 🎶
    9.5 Find the longest substring with two unique characters 🎶 👍
    9.6 Find the longest substring with k unique characters
    9.7 Find the longest substring with non-repeating characters
    9.8 Longest Substring with At Most K Distinct Characters 🎨 👍
    9.9 Find the minimum length of the substring that contains all characters in a given input 🚀
    10.Given an input string and pattern find the minimum window in the input string that will contain all the characters in the pattern 🎶 🚀
  10. Find the first non repeating character in string

Linked Lists

  1. Linked List Library 👍 💥
  2. Linked List Introduction
    2.1 Single Linked Lists
    2.2 Double Linked Lists
  3. Find the nth node from the end of a linked list 🎶 💡
  4. Circular Linked List, Cycle & Intersection
    4.1 Find the length and start node for the cycle in a linked list 💡 🎶
    4.2 Find the node at which the intersection of two single linked lists begins
    4.3 Add a node to a sorted circular linked list 💡 🎶
  5. Merge
    5.1 Merge two sorted linked lists [TODO]
    5.2 Merge K sorted linked lists [TODO] 💥
  6. Given a single linked list with one digit positive integer value
    6.1 Add 1 [TODO]
    6.2 Add given value [TODO]
  7. Reverse a linked list 👍 🚀
  8. Check if a linked list is a Palindrome
  9. Find the middle element in a linked list 💡
  10. Delete a node in the linked list 🎶 💥
  11. Zip a linked list 🎶 🚀
  12. Split a link list into odd and even values with no additional space 🚀
  13. Remove duplicate values & retain order of existing values 💥
  14. Design and implement Least Used Cache (LRU) 💡 🎶 🚀
  15. Implement skip list
  16. Given linked list return max value at any given time in constant time
  17. Swap adjacent nodes of a linked list [TODO]
  18. Return a linked list that contains the intersection of two linked lists 🎶

Stacks

  1. Implement stack using list
  2. Implement stack using linked list
  3. Implement stack using dynamic array
  4. Implement stack using fixed size array
  5. Implement stack with getMax() that operates in constant time 📝
  6. Check if a string containing parenthesis'()' is balanced 📝
  7. Check if a string containing just the characters '(', ')', '{', '}', '[' and ']'is balanced
  8. Find the length of the longest valid parenthesis sequence in a string, in O(n) time 🎶 👍
  9. Given a string where each character can be [0-9] or [+-*] find the result 👍
  10. Find top 3 and bottom 2 values from the list in O(n) 👍
  11. Implement stack using queue [TODO]
  12. Compute largest rectangle area under a histogram 🚀 🎶 🎨
  13. Design an algorithm for computing the k-th largest element in a sequence of elements. It should run in O(n) expected time where n is the length of the sequence, which is not known in advnance. The value of K is known in advance. Print the k-th largest element after the sequence has ended. It should use O(k) additional storage [TODO]
  14. Expression evaluator 🚀
    14.1 Single digit
    14.2 Multiple digits
  15. Find longest file path 🎨

Queue & Double-ended Queue

  1. Implement queue using list
  2. Implement queue using linked list
  3. Implement a queue using two stacks
  4. Queue implementation using dynamic array
  5. Queue implementation using fixed size array
  6. [Design an algorithm to sort a stack in descending order] (https://github.com/harishvc/challenges/blob/master/sort-stack-in-descending-order.py)
  7. Sliding Window Maximum 🚀 🎶 💥
  8. Implement getMax() that operates in constant time 🚀
    8.1 Given a queue return max value at any given time in constant time
    8.2 Given linked list return max value at any given time in constant time
  9. Given a screen with all pixels having one of two colors. When a random pixel is clicked, then that pixel & all the adjacent pixels with same color should change the color to the second color [TODO]
  10. Implement blocking queue [TODO]
  11. Implement non-blocking queue [TODO]

Binary Trees

  1. Binary Tree Traversal Library 👍 🚀
    1.1 Pre-order
    1.2. In-order
    1.3. Post-order
    1.4 Level-order
  2. Essentials
    2.0 Binary Tree Essentials Library 👍 🚀
    2.1 Find # of leaves, half nodes and nodes in a binary tree
    2.2 Find the size of a binary tree
    2.3 Find the height (max depth) of the binary tree 🎶 👍
    2.4 Find the depth (level) of a node and the path from the root
    2.5 Find the deepest node in binary tree
    2.6 Find diameter (width) of a binary tree 👍 🎶 💡
    2.8 Find all edge nodes (boundary/perimeter) in the binary tree 👍
  3. Path Sum
    3.1 Find the max value of the binary tree
    3.2 Find level than has maximum sum 👍
    3.3 Given path sum check if the path exists 👍
    3.4 Root to leaf path (Iterative)
    3.5 Root to leaf path (Recursive) 🎨 💡
    3.6 Find the sum of all root to leaf paths where each path represents a binary number 👍 📝 💡
    3.7 Find sum of all leaf nodes
    3.8 Find the sum of all left leaves
  4. Moderate Difficulty
    4.1 Flip/Invert a binary tree 👍
    4.2 Clone a binary tree 👍
    4.3 Check if a binary tree is symmetric (mirror)
    4.4 Check if two binary trees are structurally identical? 👍
    4.5 Complete Binary Tree
          4.5.1 Find # nodes in a Complete Binary Tree 💡 🚀
          4.5.3 Check if a Binary Tree is Complete Binary tree?
    4.6 Balanced Binary Tree
          4.6.1 Check if a binary tree is fully balanced 👍 💡
          4.6.2 Add a node to a balanced binary tree
          4.6.3 Given a full binary tree, add a pointer to the next sibling
    4.7 Given two binary trees T1 and T2, check if T2 is a subset of T1 💡 🎶 👍
    4.8 Find the ancestors of a node in a binary tree 👍 🎶 🚀
    4.9 Find the Lowest (nearest/first) Common Ancestor (LCA) of two nodes in a binary tree
          4.9.1 Traverse down - parent node to child node 👍 🎶 🚀
          4.9.2 Traverse up - child node to parent node
    4.10 Find the shortest path between two nodes in a binary tree 👍 🎶 🚀
          4.10.1 solution 1: Modify LCA
          4.10.2 solution 2: Using root to node path
    4.11 Given a binary tree where path are from parent node to child node, root and leaf can be excluded in the path
          4.11.1 Count # path that add up to a given value 💡 👍
          4.11.2 List all the path that add up to a given value 👍
    4.12 Serialize and Deserialize a Binary tree 💥 👍 🚀
          4.12.1 From pre-order with leaves and half-nodes marked 💡
          4.12.2 From pre-order & in-order
          4.12.3 From post-order & in-order
    4.13 Given preorder and inorder traversal construct postorder traversal 💥 👍
    4.14 Construct a binary tree from per-order traversal where leaf nodes are marked 💡 🎶

Binary Search Tree (BST)

  1. BST Library (add node,delete node, isBST? max, min)
  2. Create BST
    1.1 Convert a unsorted list to BST
    1.2 Convert a sorted list to BST 🎶
  3. Delete node from BST 👍
  4. Find max value of BST
  5. Find min value of BST
  6. Find if an element exists in BST
  7. Check if valid BST 👍
  8. Find inorder successor of node N 🚀 🎨 📝 🎶
  9. In a BST given a target find a value close to the target
  10. Find smallest K in a BST 👍 💡
  11. Find largest K in a BST 👍 💡 🚀
  12. Given a BST find # nodes that lie in the given range
  13. Search in sorted list X for index i such that X[i] = i 💡 👍
  14. Given a sorted list create a BST with minimal height 👍 💡
  15. Given ordered nodes construct a fully balanced BST 👍
  16. Find all possible combinations that can generate identical Binary Search Tree (BST) 💡 👍 📝 🎨
  17. Given a sorted list and a value, find the first and last occurance of the value 💡 🎶
  18. Find the square root of an integer without using square root function 💡
  19. Find mean of a BST
  20. Find the Lowest (nearest/first) Common Ancestor (LCA) of a BST 💡 🎶
  21. Find depth of a binary search tree without using recursion
  22. Implement BST iterator 🚀 💡 🎶
  23. Find size of BST tree in a Binary Tree 🎶 🚀
  24. Delete nodes outside the given range in BST 💡 🎶

Heap

  1. Fundamentals
    1.1 Convert unsorted list to max heap in linear time 📝 🚀
    1.2 Insert value into a heap 🚀
    1.3 Check if a Binary tree is a Complete Binary Tree [TODO]
    1.4 Heap Sort
  2. Moderate
    2.1. Find Kth maximum in an unsorted list
    2.2. Find the Kth most popular value in an unsorted list
    2.3. Find K popular values in an unsorted list
  3. Advanced
    3.1 Merge K sorted list of size N
    3.2 Maintain a Max Heap of size K

Graph

  1. Fundamentals
    1.1 Directed Acyclic Graph (DAG)
    1.2 Depth First Traversal
    1.3 Breadth First Traversal 👍 💥
    1.4 In a directed graph given two nodes find out whether if a path exists
    1.5 Topological Sort (given edges)
    1.6 Topological Sort using Kahn's algorithm (given adjacency list) 🎶 🚀
  2. Moderate
    A cycle is a closed path - visit a node for the second time before all its decendents have been visited
    2.1 Detect cycle using Depth First Traversal 👍 🎶
    2.2 Detect cycle using Topological Sort
    2.3 Given a sorted dictionary (array of words) of an alien language, find order of characters in the language
    2.4 Given a trip start and destination print the itenary
    2.5 Find longest path in a Directed Acyclic Graph from a source vertex 💥
  3. Advanced
    3.1 Dijkstra shortest path algorithm [TODO]
    3.2 Given a source word, target word and dictionary, transform the source word to target by changing/adding/removing 1 character at a time, while all intermediate words being valid words in the dictionary. Return the transformation chain which has the smallest number of intermediate words #WordLadder 📝 👍
    3.3 Given a boolean 2D matrix, find the number of islands 🎶 🚀
    3.4 Given a graph find the Strongly Connected Components (SSC) 🎶 🚀

Dynamic Programming

  1. Multiply two numbers without using operators *, / and with minimal operations 👍
  2. Find the power set 🎶 💡
    Power Set is a set that includes all the subsets including an empty set and the set itself.
    2^N subsets for a set of size N
  3. Generate all possible N pairs of balanced parentheses 🚀 💡
  4. Find string combinations of length K
  5. Find all permutations of a string in sorted (lexicographic) order - should handle duplicate values 🎶 🚀 💡
  6. Given stock prices during a time period find maximum gain
    6.1 singe purchase and sale 📝
    6.2 Multiple single purchases and sales without overlaps 🎨 👍
  7. Partition
    7.1 Can the given list be partitioned into two sub-lists with equal sum (balanced partition)?🎶
    7.2 Given a list, identify two sub-lists with equal sum (balanced partition, using DP) 🚀 💡
    7.3 Given a list, identify all sub-lists with equal sum (balanced partition, using back tracking) 🎶
  8. Longest Increasing Subsequence (LIS)
    8.1 Given a list of random numbers. Find length of Longest Increasing Subsequence (LIS) and the sequence 🎶
    8.2 Given a list of random numbers. Find all the increasing subsequences
  9. Given n stairs to reach the top and you can take 1 or 2 steps at each stair
    9.1 Find #ways a person can reach the top of the stairs 🎶
    9.2 Find all possible combinations 💡
  10. Given target and possible values
    10.1 Find #combinations to achieve the target 🎶 🚀
    10.2 Find all unique combinations to achieve the target 🎨
  11. Given denominations and a total
    11.1 Minimum # coins needs to reach the total and what are the coins? 🚀 🎶
    11.2 Find all possible combinations to reach a total 💡 💥
    11.3 Find all possible combinations to reach a total using lookup 💡 💥
  12. Determine the maximum possible value from the coin play game 🚀 🎶 💡
  13. What is the minimum attempts to find out from which floor egg will break?
    13.1 2 Eggs 🎨 🚀 💡
    13.2 N eggs 🎶 🚀
  14. How many different 10-digit numbers can be formed starting from 1? movement from 1 digit to the next is similar to the movement of the Knight in a chess game 💡 🚀
  15. Find the nth Fibonacci number
    15.1 Iterative, Recursive, Bottom-up & Top-down
    15.2 Recursive with lookup
  16. Longest Common Subsequence (LCS) 💥 👍
    subsequence is a generalization of substring. For example, "Itwastimes" is a subsequence of "It was the best of times", but not a substring
    16.1 Length of the LCS
    16.2 Find the LCS
    16.3 Find all the sequences 🚀
    16.4 Implement Unix diff command
  17. Longest Common Substring
    17.1 Length of the Longest Common Substring
    17.2 Find the Longest Common Substring
    17.3 Longest common substring of more than two strings
  18. Find #steps to convert string1 to string 2 using operations insert,remove,replace 👍 🚀
  19. Input string and dictionary of words
    19.1 Can the input word be split using space-separated sequence of dictionary words? 🎶 🎨
    19.2 Construct all possible sentences where each word is a valid dictionary word 💡 🚀
  20. Given two sequences find the longest palindrome
  21. Text justification
    21.1 Given a string and limit provide line breaks based on even distribution of empty spaces 💡 🎶
    21.2 Pack your words in a greedy approach, evenly distribute space TODO
  22. Binary matrix
    22.1 Find #path from top left to bottom right 💡
    22.2 Find out the maximum square size sub-matrix 🚀 🎶
    22.3 Find area of the largest rectangle 🚀 💡 🎶
    22.4 Find #rectangles
  23. Matrix multiplication
    23.1 Find the most efficient way to multiply these matrices 🎶 💡
    23.2 Find the order in which the matrices need to be multiplied
  24. Given the weight and a value of cakes and a duffel bag with max capacity, find the max value that can be filled in the duffel bag 💡 🎨

Design & Algorithms

  1. Given a million points (x, y), give an O(n) solution to find the n points closest to (0, 0)
  2. Implement T9
  3. How to find list of possible words from a letter matrix (Boggle)
  4. Given a family tree, find oldest sisters of the given person, oldest sister in the family tree and the oldest ancestor
  5. Design a command line alarm clock
  6. Design a rate limiting web service 💥 💡 🎶
  7. Using OOP design a elevator 🎶
  8. Design a data structure that implements insert, remove, contains and get random in O(1) time 💡 🚀 👍
  9. Design a data structure that implements increment, decrement, max and min in constant time 🎨 🎶 🚀
  10. Implement a function that inserts, deletes and getrandom in O(1) time 🎶 💡
  11. Write a function that returns values randomly, according to their weight 💡 🎶

Algorithms and Data Structures Resources

Python Resources

Interview Resources

Amazing Technical Discussions

GitHub Resources

You can’t perform that action at this time.