Interview prep
Patterns
Short guides to the patterns Algofily trains. Each one shows how to recognize the pattern, a worked example, and the problems that practice it.
Recognition guides compare the signals that tell these patterns apart. How to approach a coding problem you have never seen is the routine for a prompt that is not on your list.
Sliding Window
4 problems · 1 easy, 2 medium, 1 hardKeep a moving slice of an array or string and update it as its ends move, instead of rescanning from every starting point.Read the patternTwo Pointers
7 problems · 5 easy, 2 mediumKeep two indexes on a sequence and move them by a rule, instead of restarting the scan from every position.Read the patternHash Map
8 problems · 4 easy, 3 medium, 1 hardStore a value under a key so a later question — have I seen this, or which index held it — is one lookup.Read the patternPrefix Sum
2 problems · 1 easy, 1 mediumKeep a running total from the start of the row, so a later range is one subtraction instead of a fresh loop.Read the patternBinary Search
5 problems · 2 easy, 2 medium, 1 hardCut a sorted range in half. The middle value tells you which side can still hold the answer, so the other side is discarded.Read the patternStack
4 problems · 2 easy, 2 mediumRemember unfinished work in last-in, first-out order. Push when something opens, and pop when a later item resolves it.Read the patternQueue
1 problem · 1 easyServe items in the order they arrived. New work joins the back. The next item to handle is the one that has been waiting longest.Read the patternDepth-First Search
8 problems · 2 easy, 5 medium, 1 hardFollow one branch until it ends, then return and take the next. The open path is a stack: the node you entered last is the one you finish next.Read the patternFast and Slow Pointers
4 problems · 2 easy, 2 mediumWalk a chain with two runners at different speeds. The gap between them measures the middle, a loop, or a node counted from the end, without an index and without a second full pass.Read the patternBreadth-First Search
4 problems · 3 medium, 1 hardVisit nodes in the order they were discovered, one layer at a time. When every edge costs the same, the first time you reach a target is the fewest steps.Read the pattern