Logo for ammarahmed.ca

Medium

Solutions and thought process for medium difficulty Leetcode problems.

Medium
Oct 06, 2025

146. LRU Cache

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

#linked-list
#OOD

Medium
Oct 05, 2025

56. Merge Intervals

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

#stack

Medium
Oct 04, 2025

200. Number of Islands

Given an m x n 2D binary grid grid which represents a map of '1' s (land) and '0' s (water), return the number of islands.

#graph
#matrix

Medium
Jul 28, 2025

567. Permutation in String

Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

#sliding-window

Medium
Jul 27, 2025

424. Longest Repeating Character Replacement

You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.

#sliding-window

Medium
Jun 14, 2025

3. Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without duplicate characters.

#sliding-window

Medium
Jun 12, 2025

875. Koko Eating Bananas

Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.

#binary-search

Medium
May 27, 2025

155. Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

#stack
#class

Medium
May 25, 2025

128. Longest Consecutive Sequence

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

#arrays
#math

Medium
May 24, 2025

49. Group Anagrams

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

#arrays
#hashing