Algorithms & Data Structures

Boopathi's LeetCode Solutions in Python

I write these up as I work through problems — not as answer keys, but as an explanation of how you get to the answer. Every page summarises the problem in my own words, shows the brute force first so the inefficiency is visible, then derives the solution worth writing.

Solutions

1. Two Sum

brute force and the one-pass hash map, with complexity analysis, a worked example and the mistakes people make.

EasyArrayHash Table

20. Valid Parentheses

why a counter is not enough, full complexity analysis and the edge cases that break naive solutions.

EasyStringStack

121. Best Time to Buy and Sell Stock

the single-pass running-minimum approach, why order matters and full complexity analysis.

EasyArrayDynamic ProgrammingGreedy

206. Reverse Linked List

the iterative three-pointer method and the recursive version, with complexity analysis and a pointer-by-pointer walkthrough.

EasyLinked ListRecursion

How each write-up is structured

Every solution page follows the same shape, so you can skip to the part you need:

  1. The problem restated in original wording, with a link to the official statement on LeetCode
  2. How to think about it — the reframing that makes the solution obvious
  3. The brute-force approach, written out rather than dismissed
  4. The optimised approach and the Python code
  5. Time and space complexity, with the reasoning behind both
  6. A step-by-step walkthrough on a concrete input
  7. Common mistakes, including the ones that pass small tests and fail real ones
  8. Related problems that use the same idea

These are my own explanations and my own code. Problem statements are paraphrased — no LeetCode text, editorials or test data are reproduced here.

Topics

The categories I work through, in roughly the order I found useful:

  • Arrays — Scanning, indexing and the “remember what you have seen” patterns. (solutions published)
  • Strings — Parsing, character counting and stack-based structure checks. (solutions published)
  • Hash Tables — Trading memory for lookup speed — the move behind most linear-time solutions. (solutions published)
  • Two Pointers — Walking a sequence from both ends, or at two speeds.
  • Sliding Window — Running totals and running extremes over a moving range.
  • Binary Search — Halving a sorted search space, and the off-by-one traps in it.
  • Linked Lists — Pointer rewiring, cycle detection and in-place reversal. (solutions published)
  • Trees — Traversal orders, recursion and the iterative equivalents.
  • Graphs — BFS, DFS and the shortest-path problems built on them.
  • Dynamic Programming — Finding the subproblem, then removing the recursion.

I add write-ups as I go rather than publishing a page per problem for its own sake, so this list grows slowly and deliberately.

More of Boopathi's work

If you came here from a search for algorithm solutions, the rest of the site is project work: Boopathi's projects covers full stack web and IoT builds, Boopathi's developer blog has longer technical write-ups, and the profile page is the short version of who I am.