Category · 58 articles
Algorithm
Tracking Down the Mystery: Finding the Unique Delivery ID
Here's a fun one. A drone delivery company logs every delivery ID twice — once at takeoff, once at landing. One morning, a drone doesn't come back. You ha...
13 May 2024
Elusive Least Occurring Number in an Array
Given an array of integers, find the number that appears the fewest times. If there's a tie, return any of them.
6 May 2024
Solving the Height of a Binary Tree Puzzle
You get an array like [1, 2, 3, 4, -1, -1, -1]. It represents a binary tree. -1 means null. Find the height.
6 May 2024
Harry Potter Discounts: A Code Challenge Algorithm
This is one of my favorite code katas. A bookshop sells 5 Harry Potter books at 8 EUR each. Buy different titles together and you get a discount:
30 Apr 2024
Implementing a Task Heap Service in TypeScript
Imagine a task queue where you always want to run the shortest task first. A sorted array would work, but inserting into a sorted array is O(n). A min-hea...
29 Apr 2024
Text Highlighting Algorithm in TypeScript
I needed to highlight search matches in a string. Not with regex replacement — I had specific character index ranges that needed wrapping with tags.
25 Apr 2024
Finding a Path in a 2D Array using TypeScript
You have a grid. Some cells are open (0), some are walls (1). Find a path from the start to the destination. You can move up, down, left, or right.
22 Apr 2024
Longest Substring that contains no repeated Characters Algorithm
Given a string, find the length of the longest substring with no repeated characters.
22 Apr 2024
Trie Algorithm for Efficient Autocomplete
Type "pro" into a search bar and get suggestions like "programming", "product", "project." That's autocomplete. Behind it, there's often a Trie.
20 Apr 2024
Efficient Search and Insertion in Sorted Arrays: Algorithm
Here's a common interview problem: given a sorted array, find where a target value is — or where it should be inserted to keep the array sorted.
19 Apr 2024
Pokemon Game Algorithm
This is a real take-home challenge I've encountered. It's not about finding the optimal algorithm — it's about demonstrating clean domain modeling, OOP pr...
10 Apr 2024
Implement a HashMap Algorithm
Every language gives you a built-in hash map. But building one from scratch teaches you what's actually happening under the hood — and why performance can...
10 Apr 2024
Word Pattern Algorithm
Given a pattern like "abba" and a string like "dog cat cat dog", check if the string follows the pattern. Each letter maps to exactly one word, and each w...
8 Apr 2024
Length of Last Word Algorithm
Given a string of words and spaces, return the length of the last word.
8 Apr 2024
Ransom Note Algorithm
Can you build the ransom note using only letters from the magazine? Each letter in the magazine can only be used once.
29 Mar 2024
Minimum Size Subarray Sum Algorithm
Given an array of positive integers and a target, find the smallest contiguous subarray whose sum is at least the target. If no such subarray exists, retu...
28 Mar 2024
Valid Palindrome Algorithm
A palindrome reads the same forwards and backwards. But real-world strings have uppercase letters, spaces, punctuation. The actual check is: after strippi...
28 Mar 2024
H-Index Algorithm
The H-Index measures a researcher's impact. It's the largest number h such that the researcher has at least h papers with h or more citations each.
28 Mar 2024
Jump Game II Algorithm
You're at the start of an array. Each element tells you the maximum distance you can jump forward from that position. Find the minimum number of jumps to ...
28 Mar 2024
Jump Game Algorithm
You have an array of integers. You start at index 0. Each number tells you the maximum distance you can jump forward from that position.
28 Mar 2024
Best Time to Buy and Sell Stock II Algorithm
This is a twist on the classic stock problem. You can buy and sell as many times as you want — but you can only hold one share at a time.
27 Mar 2024
Best Time to Buy and Sell Stock Algorithm
You get one shot. Buy once, sell once. Find the maximum profit.
27 Mar 2024
Rotate Array Algorithm
Rotate an array to the right by k steps. In-place. O(1) extra space.
27 Mar 2024
Remove Duplicates from Sorted Array II Algorithm
The previous problem said "no duplicates at all." This one says "each element can appear at most twice." Small rule change, same core technique.
27 Mar 2024
Remove Duplicates from Sorted Array Algorithm
You have a sorted array of integers. Remove duplicates in-place so each value appears only once. Return the count of unique elements.
27 Mar 2024
Remove Element Algorithm
Given an array and a target value, remove every occurrence of that value in-place. Return how many elements remain.
27 Mar 2024
Merge Sorted Array Algorithm
Two sorted arrays. Merge them into one sorted array — in place, inside the first array.
27 Mar 2024
Open Addressing Algorithm In Hash Tables
Hash tables are fast — O(1) average lookups. But what happens when two keys hash to the same slot?
22 Mar 2024
Get Most Cookie Used
This is a real interview challenge I've seen. You get a CSV log of cookies with timestamps. Find the most active cookie for a given date.
21 Mar 2024
Hashing Algorithm
A hash function takes any input and produces a fixed-size number. Same input, same output. Always.
21 Mar 2024
N-Queens Problem with Backtracking Algorithm
Place N queens on an N×N chessboard so that no two queens threaten each other. No shared rows, columns, or diagonals.
21 Mar 2024
Backtracking Algorithm
I once spent hours debugging a scheduling system that needed to find valid combinations from a huge set of options. Nested loops weren't cutting it. What ...
21 Mar 2024
Activity Selection Algorithm
You have a conference room. Ten meetings want to use it. Some overlap. How do you fit the most meetings into a single day?
21 Mar 2024
Prim Algorithm
Prim's algorithm finds the Minimum Spanning Tree (MST) of a weighted graph. The MST connects all vertices with the minimum total edge weight — no cycles.
21 Mar 2024
Substring Search Algorithms
Find where a pattern appears inside a larger text. It's the engine behind Ctrl+F, grep, and every search bar you've ever used.
21 Mar 2024
Binary Search Trees (BSTs) Algorithm
A sorted array gives you fast search but slow inserts. A linked list gives you fast inserts but slow search. A Binary Search Tree tries to give you both.
20 Mar 2024
Tree traversal Algorithms
A tree is a collection of nodes connected by edges. Traversal means visiting every node exactly once. The question is: in what order?
20 Mar 2024
Longest Common Subsequence Algorithm
Given two strings, find the longest sequence of characters that appears in both — in the same order, but not necessarily next to each other.
20 Mar 2024
Knapsack Problem Algorithm
You have a bag with a weight limit. You have a pile of items, each with a weight and a value. Which items do you pick to maximize value without exceeding ...
20 Mar 2024
Kruskal Algorithm
You have a network of cities. Roads connect them, each with a construction cost. You need to connect every city while spending as little as possible. No l...
20 Mar 2024
Depth-First Search (DFS) Algorithm
DFS goes deep before going wide. It picks a direction and follows it as far as possible. When it hits a dead end, it backtracks and tries the next path.
19 Mar 2024
Merge Sort Algorithm
Merge sort splits an array in half, sorts each half, then merges them back together in order. It keeps splitting until every piece is a single element — a...
19 Mar 2024
Insertion Sort Algorithm
Imagine you're sorting playing cards. You pick up each card and slide it into the right spot among the cards already in your hand. That's insertion sort.
19 Mar 2024
Selection Sort Algorithm
Selection sort does exactly what the name says. Scan the unsorted portion, select the smallest element, swap it into position. Repeat.
19 Mar 2024
Sudoku Algorithm and Problem
Sudoku is the perfect backtracking problem. You have a 9x9 grid. Fill every cell with 1-9. No repeats in any row, column, or 3x3 box.
16 Mar 2024
String Reversal Algorithm
Reverse a string. "hello" becomes "olleh". It's the "Hello, World!" of algorithm problems — but there's more depth here than you'd expect.
15 Mar 2024
Dijkstra's Algorithm
BFS finds the shortest path when every edge costs the same. But what if edges have different weights? That's where Dijkstra's algorithm comes in.
13 Mar 2024
Breadth-First Search (BFS) Algorithm
BFS explores a graph like ripples in a pond. Drop a stone at the start node. First you visit everything one step away. Then two steps. Then three. Level b...
13 Mar 2024
Quick Sort Algorithm
Pick an element (the pivot). Move everything smaller to the left, everything larger to the right. Now the pivot is in its final position. Recurse on both ...
13 Mar 2024
Fibonacci Sequence Algorithm
The Fibonacci sequence is every programmer's first encounter with recursion — and with why naive recursion can destroy performance.
12 Mar 2024
Binary Search Algorithm
Imagine looking up a word in a dictionary. You don't start at page one. You flip to the middle, see if the word comes before or after, and halve your sear...
12 Mar 2024
Maximum Subarray Algorithm
Given an array of integers, find the contiguous subarray with the largest sum.
12 Mar 2024
Merge Two Sorted Lists Algorithm
Two sorted lists. Combine them into one sorted list.
12 Mar 2024
Valid Parentheses Algorithm
Given a string containing (, ), {, }, [, ], determine if the parentheses are valid.
10 Mar 2024
Roman to Integer Algorithm
Seven symbols. That's the entire Roman numeral system: I (1), V (5), X (10), L (50), C (100), D (500), M (1000).
10 Mar 2024
Palindrome Algorithm
A palindrome reads the same forwards and backwards. "racecar" is one. "A man, a plan, a canal, Panama!" is too — once you strip out spaces and punctuation.
10 Mar 2024
Two Sum Algorithm
You have a list of numbers and a target. Find two numbers that add up to the target. Return their indices.
10 Mar 2024
Reverse Integer Algorithm
Reverse the digits of an integer. Keep the sign. Return 0 if the result overflows a 32-bit signed integer.
10 Mar 2024