Git Product home page Git Product logo

coding-exercises's Introduction

This repository contains my implementation of useful data structures, algorithms, games, as well as my solutions to programming puzzles.

Each item is marked with a difficulty level. 1 - easy 2 - medium 3 - hard

If a file name starts with 'lc', it's a problem from leetcode.com

Written in python3. Thanks Danijar Hafner (@danijar) for the inspiration.

Data structures

Linked lists

  • List class (linked_list.py) - 1
  • Remove duplicates (linked_list_algos.py)
  • Find nth last element (linked_list_algos.py)
  • Remove node given only its object (linked_list_algos.py)
  • Sum linked lists with one digit per node (linked_list_algos.py)
  • Find beginning of circle (linked_list_algos.py)

Trees

  • Binary heap class (binary_heap.py) - 2
  • Binary tree class (binary_tree.py) - 1
  • Binary search tree class that allows duplicate values (binary_search_tree.py) - 2 BST class inherits binary tree class
  • Red black tree class (red_black_tree.py)
  • B+ tree class (b_tree.py) - 3
  • Trie class that allows word removal (trie.py) - 2
  • Check if a binary tree is a binary search tree (binary_tree_algos.py) - 2
  • Check if a binary tree is balanced (binary_tree_algos.py)
  • Find first common ancestor of two nodes in a binary tree (binary_tree_algos.py)
  • Get all nodes of depth n in a binary tree (binary_tree_algos.py)
  • Given two large trees, check if the first is a subtree of the second (binary_tree_algos.py)
  • Find all sub paths in a binary tree that sum up to x (binary_tree_algos.py)
  • Create a balanced binary search tree from a sorted array (bst_algos.py)

Graphs

  • Undirected graph class
  • Directed graph class
  • Breadth first search (search.py)
  • Depth first search (search.py)
  • A-star (search.py)

Stacks and queues

  • Queue class (queue.py)
  • Heap priority queue (priority_queue.py) - 1
  • Stack class (stack.py)
  • Stack that finds min in O(1) (min_stack.py)
  • Solve Hanoi towers using stacks (stack_algos.py)
  • Sort stack using only push, pop, peek and empty (stack_algos.py)
  • Build a queue using two stacks (stack_algos.py)

Algorithms

Sorting

  • Insertion sort (sort.py) - 1
  • Selection sort (sort.py) - 1
  • Merge sort (sort.py) - 2
  • Heap sort (sort.py) - 2
  • Quick sort (sort.py) - 2
  • Counting sort (sort.py) - 2
  • Radix sort (sort.py) - 2
  • Bucket sort (sort.py) - 2

Dynamic Programming

  • Computing a Fibonacci sequence
  • Find the longest common subsequence between two strings

Recursion

  • Find all permutations of a string
  • Find all subsets of a set
  • Find all proper combinations of n parentheses
  • Bucket fill
  • Check if it's possible to make a change with a set of coins
  • Check if it's possible to weight two objects with a set of weights
  • Eight queen

Programming Puzzles

String Manipulation

  • Check if two strings are anagrams in O(n + m) time (anagrams.py) - 1
  • Find the longest palindromic substring in O(n^2) time (lc_longest_palindrome.py) - 2
  • Check if a string has balanced delimiters in O(n) time (delim_balanced.py) - 2
  • Reverse words while maintaining spaces and tabs in O(n) time (reverse_words.py) - 2
  • Longest substring without repeating characters in O(n) time (lc_longest_nonrepeat_substring.py) - 2
  • Longest contiguous substring of 2 distinct characters in O(n) time (substring_two_chars.py) - 2
  • Remove duplicate chars in a string
  • Encode and decode Caesar cipher (caesar.py)
  • Check if a string is a rotation of another

Mathematical

  • Reverse integers (lc_reverse_int.py) - 1
  • Sieve of Eratosthenes (sieve_prime.py) - 1
  • Two sum in O(n) time (lc_two_sum.py) - 1 Given an array of integers, return indices of the two numbers such that they add up to a specific target.
  • Year with maximum population (year_max_pop.py) - 1 Given a list of people with their years of birth and death, find the year with max population
  • FizzBuzz (fizzbuzz.py) - 1
  • ZigZag conversion (lc_zigzag_convert.py) - 2
  • Find sum of all subarrays of an array (subarray_sum.py) - 2
  • Add two numbers, each represented by a reverse linked list (lc_add_number_reverse.py) - 2
  • Find the median of two sorted arrays in O(log(m+n)) time (lc_median_arrays.py) - 3
  • Find nth smallest number that can be created using a list of prime factors
  • Count occurences of given digit in all numbers up to n
  • Rotate N x N matrix in place

coding-exercises's People

Contributors

chiphuyen avatar kgashok avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.