Binary Search on Answer
A powerful interview pattern where you binary search the range of possible answers instead of searching inside a sorted array.
Interview Prep
Reusable interview problem-solving patterns: binary search, sliding window, monotonic stack, heaps, backtracking, graph traversal, and more.
Showing 9 of 9 questions
A powerful interview pattern where you binary search the range of possible answers instead of searching inside a sorted array.
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.
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.
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.
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.
Learn the two main binary search templates: one that discards mid and one that keeps mid as a candidate.
Practical Java sorting examples using streams, comparators, Collections.sort, PriorityQueue for top N, and Map.Entry sorting.
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.
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.