Given an array of positive integers, find the shortest contiguous subarray whose sum is at least k.
Because all numbers are positive, the window sum grows monotonically. This allows a variable-size sliding window. If negatives were allowed, this would NOT work.
Given an array that may contain negative numbers, find the shortest subarray with sum at least k.
Sliding window fails when negative numbers are present because the sum is no longer monotonic. This becomes a prefix sum + monotonic deque problem.
Find the kth smallest element in an unsorted array.
While sorting works (O(n log n)), the optimal pattern is a heap of size k (O(n log k)). This is a Top-K pattern.
Given a sorted array of integers, find the number of occurrences of a target.
Even though it sounds like counting, the sorted property allows binary search to find first and last positions in O(log n).
You are given a grid where each cell has a time when it becomes passable. Find the minimum time to reach the bottom-right cell.
Because movement cost varies by time constraints, this is a shortest path with weights problem. That requires Dijkstra, not simple BFS.
Given intervals, determine if a person can attend all meetings.
Sort intervals by start time and check for overlap. This is a greedy interval scheduling pattern.
Find the longest increasing subsequence.
The optimal O(n log n) solution uses patience sorting idea with binary search. Many candidates incorrectly attempt sliding window.
Given a string, find the longest palindromic substring.
Although it contains the word 'substring', sliding window does NOT work. Palindromes require center expansion or DP.
You are given n cities and connections between them. Determine the number of connected components.
This is a classic connectivity problem in a graph. Use DFS/BFS or Union-Find.
Find the maximum length subarray with equal number of 0s and 1s.
Convert 0 to -1 and track prefix sums. When the same prefix sum appears again, the subarray between them has equal 0s and 1s.
What These Questions Test
- Do you understand when sliding window fails?
- Can you detect weighted vs unweighted graph?
- Can you recognize prefix sum transformations?
- Can you detect when binary search is hidden?
- Can you avoid keyword traps like ‘substring’?
Common Trap Signals
- Presence of negative numbers (breaks sliding window)
- Word “substring” (not always sliding window)
- “Minimum time” (could be Dijkstra)
- “Sorted” (binary search opportunity)
- “Connected components” (graph)
Premium Content
Unlock Pattern Recognition Quiz 2 and all premium lessons with a subscription.
From ₹199.99/year — See plans