Leetcode in Gleam
This project is a collection of solutions to Leetcode problems.
Wait! Give me a chance to explain!
Unlike many Leetcode problem sets, this one isn't just focused on solving (and explaining) the problems. Instead, the goal of this project is to solve Leetcode problems using recursive, immutable, and functional paradigms.
All of these solutions are solved with recursion and simple data structures, are type-safe, and do not rely on mutation. Most are solved entirely without relying on hashmaps!
Problems index
Recursive problem-solving
My background is in mathematics before I moved over to programming, so I have always had a soft spot for recursion and type-safety. These concepts map very cleanly onto how I was taught to understand logic and problem-solving, so I wanted to model out how these problems be solved in a way that aligns with my brain.
As outlined in this video ↗, you can approach almost any recursive problem with five steps:
- Define the simplest possible inputs. These will become the base cases.
- Create small examples. This step builds your intuition for how the problem steps relate to each other.
- Relate hard cases to simpler cases. This is the seed of the recursive step, but still in concrete terms.
- Generalize the pattern. Take the recursive seed and create the full recursive rule, defining the n+1 case from the n case.
- Write the code to combine the recursive rule with the base case(s). The last step is to put it all together.
All of the problems solved in this repo include a write-up mapping my actual, real examples and reasoning with these steps and culminating in the solution.