Interview Prep

Coding Patterns

Reusable interview problem-solving patterns: binary search, sliding window, monotonic stack, heaps, backtracking, graph traversal, and more.

Showing 9 of 9 questions

Binary Search on Answer

A powerful interview pattern where you binary search the range of possible answers instead of searching inside a sorted array.

Binary SearchCoding PatternOptimizationMonotonic Predicate

Monotonic Stack and Monotonic Queue Explained

A monotonic stack or queue keeps values in increasing or decreasing order so we can answer next-greater, next-smaller, or sliding-window max/min questions efficiently.

StackQueueDequeCoding PatternArrays

What are the main sliding window patterns?

Sliding window problems use two pointers to maintain a moving range over an array or string. Common variations include fixed-size windows, variable-size windows, frequency-map windows, and monotonic-deque windows.

Coding PatternsSliding WindowTwo PointersArraysStrings

DFS vs BFS: What are the mental models?

DFS (Depth First Search) explores one path deeply before backtracking. BFS (Breadth First Search) explores level by level. The right choice depends on whether you need depth exploration, all paths, connected components, shortest path in unweighted graphs, or level-order traversal.

Coding PatternsDFSBFSGraphsTreesTraversal

DFS: iterative vs recursive — when should you use each?

Recursive DFS is simple and natural for trees and small-to-medium depth problems. Iterative DFS uses an explicit stack, avoids call-stack overflow, and gives more control for very deep graphs or production-style traversal.

Coding PatternsDFSRecursionGraphsTreesJava

Binary Search Templates

Learn the two main binary search templates: one that discards mid and one that keeps mid as a candidate.

Binary SearchTemplatesJavaCoding Patterns

Sorting techniques in Java

Practical Java sorting examples using streams, comparators, Collections.sort, PriorityQueue for top N, and Map.Entry sorting.

SortingComparatorStreamsPriorityQueueJava

PriorityQueue mental model

A PriorityQueue is still a queue, but elements are popped by priority instead of insertion order. This page explains min heaps, max heaps, comparators, and Top K Frequent Elements.

PriorityQueueHeapComparatorTop KJava

When to use Deque vs Stack

In modern Java, Deque with ArrayDeque is usually preferred over the legacy Stack class. Deque can behave like a stack, a queue, or a true double-ended queue.

DequeStackQueueArrayDequeJava