Skip to content
Rishad Rahman
All work

Algorithms · Ongoing practice

LeetCode Python

Clean, readable Python solutions to classic array and string problems, tracked on GitHub.

Stack

  • Python

Solutions

A personal practice log rather than a product. Each file is a self-contained Solution class with a quick example run at the bottom. Several solutions use single passes and in-place updates. Others, like Two Sum, are the straightforward first version.

ProblemApproach
Two SumCheck every pair (brute force)
Best Time to Buy and Sell StockOne pass, tracking the minimum price so far
Merge Sorted ArrayTwo-pointer merge
Plus OneCarry propagation from the last digit
Remove Duplicates from Sorted ArraySlow/fast pointers, in place
Remove ElementSlow/fast pointers, in place
Search Insert PositionLinear scan for the first value ≥ target
Length of Last WordReverse scan, skipping trailing spaces
Longest Common PrefixVertical character-by-character scan
Valid AnagramLength check, then per-character counts
class Solution:    def plusOne(self, digits: list[int]) -> list[int]:        for i in range(len(digits) - 1, -1, -1):            if digits[i] < 9:                digits[i] += 1                return digits            digits[i] = 0        return [1] + digits
Returns as soon as there's no carry, so the common case touches one digit.
↑ ↓ to move · Enter to open