Skip to content

aeu/legible-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Legible Algorithms

When I get stuck on something, I like to solve puzzles and implement algorithms as a form of focused distraction. This is a collection of my implementations of various things that I wrote to pass the time. They are in C++ and Obj-C because I enjoy working on those languages.

Data Structures

The data structures we take for granted. These were a lot more typing than I expected. The Red-Black tree especially was a lot of typing. You see typically see it represented in books as about 20-30 lines of pseudocode, but the reality is that it's way more than that, especially if you are making it robust.

Binary Search Tree — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (C++)
Red Black Tree — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (C++)

Sorting & Searching

Heapsort — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (Obj-C)
Mergesort — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (Obj-C)
Quicksort — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (Obj-C)
Improved Mergesort (C++)

Misc Snippets / Drop Ins

Code snippets that can be dropped in to other projects so you don't have to re-type the wheel every time.

Heap's Algorithm for generating permutations (C++)
Fibonacci number generator (C++)
Drop in, int holding, memory safe linked list (C++)

Binary tree is sort of optimized for leetcode, which uses an array in the style of [1,2,null,4,6,7,null,8...] to represent the tree. I can't use a vector of ints because of the nulls, and I don't want to use a sentinel value which may occur in real data. This implementation uses std::optional, so you can put in std::nullopt in the data array.

Drop in, int holding, memory safe binary tree (C++)
Depth first search (C++)

An implementation of trie. Never did one of these before, and it's been a hole in my knowledge for some time now. This was really fun to learn how it worked. Note that I still don't have delete working.

Trie (C++)

Puzzles & Problems

Meta

Puzzles and problems from the meta careers interview preparation portal.

Warmup

Level 1

Cafeteria (C++)
Director of Photography (C++)
Kaitenzushi (C++)
Rotary Lock (C++)
Scoreboard Inference (C++)
Stack Stabilization (C++)
Uniform Integers (C++)

Level 2

Director of Photography, Chapter 2 (C++)
Portals (C++)
Rotary Lock Chapter 2 (C++)

Preparation Hub

Balance Brackets (C++)
Balanced Split (C++)
Change in a Foreign Currency (C++)
Contiguous Subarrays (C++)
Counting Triangles (C++)
Encrypted Words (C++)
Matching Pairs (C++)
Minimum Length Substrings (C++)
Number of Visible Nodes (C++)
One Billion Users (C++)
Pair Sums (C++)
Revenue Milestones (C++)
Reverse To Make Equal (C++)
Rotational Cipher (C++)
slow-sums (C++)

Leetcode

Solutions are in a mix of Objective-C and C++ depending on what I was doing at the time. These days it's mostly C++.

Recently I've started re-visiting my old solutions to see how they held up to the test of time and improving their implementations as I've learned more.

Some of my earlier implementations were really bad. Like really, really, really bad.

As I go over these I have to keep reminding myself that this is a good thing. If I didn't look back at my code years later and see that it was bad, then that means that I haven't improved since I wrote it.

Easy

Leetcode № 1 (Easy) — Two Sum (C++)
Leetcode № 20 (Easy) — Valid Parentheses (C++)
Leetcode № 21 (Easy) — Merge Two Sorted Lists (C++)
Leetcode № 26 (Easy) — Remove Duplicates from Sorted Array (C++)
Leetcode № 27 (Easy) — Remove Element (C++)
Leetcode № 35 (Easy) — Search Insert Position (C++)
Leetcode № 88 (Easy) — Merge Sorted Array (C++)
Leetcode № 100 (Easy) — Same Tree (C++)
Leetcode № 101 (Easy) — Symmetric Tree (C++)
Leetcode № 104 (Easy) — Maximum Depth of Binary Tree (C++)
Leetcode № 112 (Easy) — Path Sum (C++)
Leetcode № 121 (Easy) — Best Time to Buy and Sell Stock (C++)
Leetcode № 125 (Easy) — Valid Palindrome (C++)
Leetcode № 136 (Easy) — Single Number (C++)
Leetcode № 169 (Easy) — Majority Element (C++)
Leetcode № 202 (Easy) — Happy Number (C++)
Leetcode № 205 (Easy) — Isomorphic Strings (C++)
Leetcode № 206 (Easy) — Reverse Linked List (C++)
Leetcode № 219 (Easy) — Contains Duplicate (C++)
Leetcode № 222 (Easy) — Count Complete Tree Nodes (C++)
Leetcode № 226 (Easy) — Invert Binary Tree (C++)
Leetcode № 242 (Easy) — Valid Anagram (C++)
Leetcode № 283 (Easy) — Move Zeroes (C++)
Leetcode № 290 (Easy) — Word Pattern (C++)
Leetcode № 303 (Easy) — Range Sum Query Immutable (C++)
Leetcode № 338 (Easy) — Counting Bits (C++)
Leetcode № 345 (Easy) — Reverse Vowels of a String (C++)
Leetcode № 349 (Easy) — Intersection of Two Arrays (C++)
Leetcode № 374 (Easy) — Guess Number Higher or Lower (C++)
Leetcode № 383 (Easy) — Ransom Note (C++)
Leetcode № 392 (Easy) — Is Subsequence (C++)
Leetcode № 408 (Easy) — Valid Word Abbreviation (C++)
Leetcode № 496 (Easy) — Next Greater Element I (C++)
Leetcode № 543 (Easy) — Diameter of Binary Tree (C++)
Leetcode № 605 (Easy) — Can Place Flowers(C++)
Leetcode № 637 (Easy) — Average of Levels in Binary Tree (C++)
Leetcode № 643 (Easy) — Maximum Average Subarray I (C++)
Leetcode № 680 (Easy) — Valid Palindrome (C++)
Leetcode № 700 (Easy) — Sarch in a Binary Search Tree (C++)
Leetcode № 724 (Easy) — Find Pivot Index (C++)
Leetcode № 872 (Easy) — Leav Similar Trees (C++)
Leetcode № 933 (Easy) — Number of Recent Calls (C++)
Leetcode № 938 (Easy) — Range Sum of BST (C++)
Leetcode № 977 (Easy) — Squares of a Sorted Array (C++)
Leetcode № 1071 (Easy) — Greatest Common Divisor of Strings (C++)
Leetcode № 1207 (Easy) — Unique Number of Occurrences (C++)
Leetcode № 1480 (Easy) — Running Sum of 1D Array (C++)
Leetcode № 1732 (Easy) — Find The Highest Altitude(C++)
Leetcode № 2215 (Easy) — Find the Difference of Two Arrays (C++)

Medium

Leetcode № 2 (Medium) — Add two Numbers (C++)
Leetcode № 3 (Medium) — Longest Substring Without Repeating Characters (C++)
Leetcode № 5 (Medium) — Longest Palindromic Substring (C++)
Leetcode № 7 (Medium) — Reverse Integer (C)
Leetcode № 8 (Medium) — String to Integer (C++)
Leetcode № 11 (Medium) — Container with Most Water (C++)
Leetcode № 15 (Medium) — 3Sum (C++)
Leetcode № 17 (Medium) — Letter Combinations of a Phone Number (C++)
Leetcode № 19 (Medium) — Remove Nth Node From End of List (C++)
Leetcode № 22 (Medium) — Generate Prentheses (C++)
Leetcode № 33 (Medium) — Search in Rotated Sorted Array (C++)
Leetcode № 34 (Medium) — Find First an Last Position of Element in Sorted Array (C++)
Leetcode № 36 (Medium) — Valid Sudoku (C++)
Leetcode № 39 (Medium) — Combination Sum (C++)
Leetcode № 40 (Medium) — Combination Sum II (C++)
Leetcode № 47 (Medium) — Permutations II (C++)
Leetcode № 48 (Medium) — Rotate Image (C++)
Leetcode № 49 (Medium) — Group Anagrams (C++)
Leetcode № 50 (Medium) — Pow (C++)
Leetcode № 53 (Medium) — Maximum Subarray (C++) Leetcode № 54 (Medium) — Spiral Matrix (C++)
Leetcode № 55 (Medium) — Jump Game (C++)
Leetcode № 56 (Medium) — Merge Intervals (C++)
Leetcode № 61 (Medium) — Rotate List (C++)
Leetcode № 71 (Medium) — Simplify Path (C++)
Leetcode № 73 (Medium) — Set Matrix Zeroes (C++)
Leetcode № 74 (Medium) — Search a 2D Matrix (C++)
Leetcode № 75 (Medium) — Sort Colors (C++)
Leetcode № 77 (Medium) — Combinations (C++)
Leetcode № 78 (Medium) — Subsets (C++)
Leetcode № 79 (Medium) — Word Search (C++)
Leetcode № 80 (Medium) — Remove duplicates from Sorted Array II (C)
Leetcode № 82 (Medium) — Remove Duplicates from Sorted List II II (C++)
Leetcode № 90 (Medium) — Subsets II (C++)
Leetcode № 92 (Medium) — Reverse Linked List II (C++)
Leetcode № 93 (Medium) — Restore IP Addresses (C++)
Leetcode № 98 (Medium) — Validate Binary Search Tree (C++)
Leetcode № 102 (Medium) — Binary Tree Level Order Traversal (C++)
Leetcode № 103 (Medium) — Binary Tree ZigZag Level Order Traversal (C++)
Leetcode № 105 (Medium) — Construct Binary Tree from Preorder and Inorder traversal (C++)
Leetcode № 116 (Medium) — Populating Next Right Pointers in Each Node (C++)
Leetcode № 117 (Medium) — Populating Next Right Pointers in Each Node II (C++)
Leetcode № 122 (Medium) — Best Time to Buy and Sell Stock II (C++)
Leetcode № 128 (Medium) — Longest Consecutive Sequence (C++)
Leetcode № 129 (Medium) — Sum Root to Leaf Numbers (C++)
Leetcode № 130 (Medium) — Surrounded Regions (C++)
Leetcode № 131 (Medium) — Palindrome Partitioning (C++)
Leetcode № 0133 (Medium) — Clone Graph (C++)
Leetcode № 134 (Medium) — Gas Station (C++)
Leetcode № 138 (Medium) — Copy List with Random Pointer (C++)
Leetcode № 139 (Medium) — Word Break (C++)
Leetcode № 146 (Medium) — LRU Cache (C++)
Leetcode № 150 (Medium) — Evaluate Reverse Polish Notation (C++)
Leetcode № 151 (Medium) — Reverse Words in a String (C++)
Leetcode № 155 (Medium) — Min Stack (C++)
Leetcode № 162 (Medium) — Find Peak Element (C++)
Leetcode № 167 (Medium) — Two Sum II - Input Array is Sorted (C++)
Leetcode № 189 (Medium) — Rotate Array (C++)
Leetcode № 198 (Medium) — House Robber (C++)
Leetcode № 199 (Medium) — Binary Tree Right Side View (C++)
Leetcode № 200 (Medium) — Number of Islands (C++)
Leetcode № 207 (Medium) — Course Schedule (C++)
Leetcode № 209 (Medium) — Minimum Size Subarray Sum (C++)
Leetcode № 210 (Medium) — Course Schedule II (C++)
Leetcode № 215 (Medium) — Kth Largest Element in an Array (C++)
Leetcode № 236 (Medium) — Lowest Commong Ancestor of a Binary Tree (C++)
Leetcode № 238 (Medium) — Product of Array except Self (C++)
Leetcode № 274 (Medium) — H-Index (C++)
Leetcode № 289 (Medium) — Game of Life (C++)
Leetcode № 314 (Medium) — Binary Tree Vertical Order Traversal (C++)
Leetcode № 325 (Medium) — Maximum Size Subarray Sum Equals K (C++)
Leetcode № 328 (Medium) — Odd Even Linked List (C++)
Leetcode № 334 (Medium) — Increasing Triplet Subsequence (C++)
Leetcode № 347 (Medium) — Top K Frequent Elements (C++)
Leetcode № 394 (Medium) — Decode String (C++)
Leetcode № 399 (Medium) — Evaluate Division (C++)
Leetcode № 406 (Medium) — Queue Reconstruction by Height (C++)
Leetcode № 417 (Medium) — Pacific Island Water Flow (C++)
Leetcode № 433 (Medium) — Minimum Genetic Mutation (C++)
Leetcode № 437 (Medium) — Path Sum III (C++)
Leetcode № 450 (Medium) — Delete Node in a BST (C++)
Leetcode № 452 (Medium) — Minimum number of arrows to burst balloons (C++)
Leetcode № 523 (Medium) — Continuous Subarray Sum (C++)
Leetcode № 525 (Medium) — Contiguous Array (C++)
Leetcode № 542 (Medium) — 1 Matrix (C++)
Leetcode № 547 (Medium) — Number of Provinces (C++)
Leetcode № 560 (Medium) — Subarray Sum Equals K (C++)
Leetcode № 649 (Medium) — Dota2 Senate (C++)
Leetcode № 670 (Medium) — Maximum Swap (C++)
Leetcode № 684 (Medium) — Redundant Connection (C++)
Leetcode № 695 (Medium) — Max Area of Island (C++)
Leetcode № 735 (Medium) — Asteroid Collision (C++)
Leetcode № 739 (Medium) — Daily Temperature (C++)
Leetcode № 763 (Medium) — Partition Labels (C++)
Leetcode № 797 (Medium) — All Paths from Source to Target (C++)
Leetcode № 802 (Medium) — Find Eventual Safe States (C++)
Leetcode № 841 (Medium) — Keys & Rooms (C++)
Leetcode № 875 (Medium) — Koko eating bananas (C++)
Leetcode № 907 (Medium) — Sum of Subarray Minimums (C++)
Leetcode № 930 (Medium) — Binary Subarrays With Sum (C++)
Leetcode № 973 (Medium) — K closest points to origin (C++)
Leetcode № 974 (Medium) — Subarray Sums Divisible by K (C++)
Leetcode № 994 (Medium) — Rotting Oranges (C++)
Leetcode № 1004 (Medium) — Max Consecutive Ones III (C++)
Leetcode № 1161 (Medium) — Maximum Level Sum of Binary Tree (C++)
Leetcode № 1248 (Medium) — Count Number of Nice Subarrays (C++)
Leetcode № 1249 (Medium) — Minimum Remove to Make Valide Parentheses (C++)
Leetcode № 1372 (Medium) — Longest ZigZag Path in a Binary Tree (C++)
Leetcode № 1448 (Medium) — Count Good Nodes in Binary Tree (C++)
Leetcode № 1456 (Medium) — Maximum Number of Vowels in a Substring of Given Length (C++)
Leetcode № 1466 (Medium) — Re-order routes to make all paths lead to the city zero (C++)
Leetcode № 1493 (Medium) — Longest Subarray of 1's after Deleting One Element (C++)
Leetcode № 1570 (Medium) — Dot Product of Two Sparse Vectors (C++)
Leetcode № 1584 (Medium) — Min Cost to Connect All Points (C++)
Leetcode № 1650 (Medium) — Lowest Common Ancestor of a Binary Tree III (C++)
Leetcode № 1657 (Medium) — Determine if two strings are close (C++)
Leetcode № 1679 (Medium) — Max Numbef of K-Sum Pairs(C++)
Leetcode № 1926 (Medium) — Nearest Exit From Entrance In Maze (C++)
Leetcode № 2095 (Medium) — Delete the Middle Node of a Linked List (C++)
Leetcode № 2104 (Medium) — Sum of Subarray Ranges (Obj-C)
Leetcode № 2130 (Medium) — Maximum Twin Sum of a Linked List (C++)
Leetcode № 2300 (Medium) — Successful Pairs of Spells and Potions (C++)
Leetcode № 2336 (Medium) — Smallets Number in an Infinite Set (C++)
Leetcode № 2352 (Medium) — Equal Row and Column Pairs (C++)
Leetcode № 3294 (Medium) — Convert Doubly Linked List To Array II (C++)

Hard

Leetcode № 23 (Hard) — Merge K Sorted Lists (C++)
Leetcode № 68 (Hard) — Text Justification (C++11,C++17).
Leetcode № 76 (Hard) — Minimum Window Substring (C++)
Leetcode № 84 (Hard) — Largest Rectangle in Histogram (C++11)
Leetcode № 124 (Hard) — Binary Tree Maximum Path Sum (C++).
Leetcode № 127 (Hard) — Word Ladder (C++)
Leetcode № 329 (Hard) — Longest Increasing Path in a Matrix (C++).

Beyond Cracking The Coding Interview

Solutions to problems from the book. Organized by category/chapter.

CH 27 — Two Pointers

27.3 — Array Intersection (C++)
27.4 — Palindromic Sentence (C++)
27.2 — Smaller Prefixes (C++)
27.5 — Reverse Case Match (C++)

CH 28 — Grids & Matrices

28.3 — Spiral Order (C++)

CH 32 — Stacks & Queues

32.1 — Compress Array (C++)
32.7 — Custom Brackets (C++)

CH 36 — Graphs

36.2 Graph Path (C++)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published