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. Maybe I'll add some Rust soon.

Data Structures

The data structures we take for granted. These were a lot more typing than I expected. The Red-Black tree especially.

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++)

Puzzles & Problems

Facebook

Balance Brackets (C)
Balanced Split (Obj-C)
Number of Visible Nodes (C)
Reverse Operations (Obj-C)
Reverse Operations C (C)

Leetcode

Leetcode has a funny subculture. If you look at the solutions, you will see very often things like "solution in 4 lines of C" or "solution in two lines of python" and so on, which reminds me of the "Obfuscated C Code" contests from back in the day.

I get that this is fun to do (and I'm also envious as this is a skill that I don't have). My implementations are a little more verbose and sometimes inconsistent, as my style has evolved over the years.

I've been going through the problems and solving them. My solutions are in a mix of Objective-C and C++ depending on what I was doing at the time.

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. This is a positive - if I didn't think my old code was bad, then that means I haven't been learning and improving over time.

Hard

Leetcode № 4 (Hard) — Median of Two Sorted Arrays (C++)
Leetcode № 23 (Hard) — Merge K Sorted Lists (Obj-C)
Leetcode № 25 (Hard) — Reverse Nodes in k-Group (C++)
Leetcode № 30 (Hard) — Substring with concatenation of all words (C++)
Leetcode № 41 (Hard) — First Missing Positive (C++).
Leetcode № 42 (Hard) — Trapping Rain Water (C++).
Leetcode № 51 (Hard) — N-Queens (C++11).
Leetcode № 52 (Hard) — N-Queens II (C++11).
Leetcode № 60 (Hard) — Permutation Sequence (C++11,C++17).
Leetcode № 68 (Hard) — Text Justification (C++11,C++17).
Leetcode № 76 (Hard) — Minimum Window Substring(C++11,C++17).
Leetcode № 84 (Hard) — Largest Rectangle in Histogram (C++11)
Leetcode № 85 (Hard) — Maximal Rectangle (C++)
Leetcode № 123 (Hard) — Best time to Buy and Sell Stock III (C++)
Leetcode № 135 (Hard) — Candy (C++)
Leetcode № 149 (Hard) — Max Points on a Line (C++)
Leetcode № 174 (Hard) — Dungeon Game (C++)
Leetcode № 188 (Hard) — Best time to Buy and Sell Stock IV(C++)
Leetcode № 218 (Hard) — The Skyline Problem (Obj-C)
Leetcode № 233 (Hard) — Number of Digit One (C++/Hard)
Leetcode № 239 (Hard) — Sliding Window Maximum(C++/Hard)
Leetcode № 1923 (Hard) — Longest Common Subpath (Obj-C)
Leetcode № 2106 (Hard) — Maximum Fruits Harvested After at Most K Steps (Obj-C)

Medium

Leetcode № 2 (Medium) — Add two Numbers(C++)
Leetcode № 7 (Medium) — Reverse Integer (C)
Leetcode № 8 (Medium) — String to Integer (C++)
Leetcode № 11 (Medium) — Container with Most Water (C++)
Leetcode № 36 (Medium) — Valid Sudoku (C++)
Leetcode № 80 (Medium) — Remove duplicates from Sorted Array II (C)
Leetcode № 151 (Medium) — Reverse Words in a String (C++)
Leetcode № 162 (Medium) — Find Peak Element (C++)
Leetcode № 199 (Medium) — Binary Tree Right Side View (C++)
Leetcode № 238 (Medium) — Product of Array except Self (C++)
Leetcode № 328 (Medium) — Odd Even Linked List (C++)
Leetcode № 394 (Medium) — Decode String (C++)
Leetcode № 450 (Medium) — Delete Node in a BST (C++)
Leetcode № 437 (Medium) — Path Sum III (C++)
Leetcode № 452 (Medium) — Minimum number of arrows to burst balloons (C++)
Leetcode № 547 (Medium) — Number of Provinces (C++)
Leetcode № 560 (Medium) — Subarray Sum Equals K (C++)
Leetcode № 695 (Medium) — Max Area of Island (Obj-C)
Leetcode № 735 (Medium) — Asteroid Collision (C++)
Leetcode № 739 (Medium) — Daily Temperature (C++)
Leetcode № 841 (Medium) — Keys & Rooms (C++)
Leetcode № 875 (Medium) — Koko eating bananas (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 № 1448 (Medium) — Count Good Nodes in Binary Tree (C++)
Leetcode № 1456 (Medium) — Maximum Number of Vowels in a Substring of Given Length (C++)
Leetcode № 1493 (Medium) — Longest Subarray of 1's after Deleting One Element (C++)
Leetcode № 1679 (Medium) — Max Numbef of K-Sum Pairs(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 № 2352 (Medium) — Equal Row and Column Pairs (C++)

Easy

Leetcode № 104 (Easy) — Maximum Depth of Binary Tree (C++)
Leetcode № 206 (Easy) — Reverse Linked List (C++)
Leetcode № 283 (Easy) — Move Zeroes (C++)
Leetcode № 345 (Easy) — Reverse Vowels of a String (C++)
Leetcode № 605 (Easy) — Can Place Flowers(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 № 1071 (Easy) — Greatest Common Divisor of Strings (C++)
Leetcode № 1207 (Easy) — Unique Number of Occurrences (C++)
Leetcode № 1732 (Easy) — Find The Highest Altitude(C++)
Leetcode № 2215 (Easy) — Find the Difference of Two Arrays (C++)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published