Practice quiz · by a Quizcard user
Coding Interview Patterns: Arrays, Hash Maps, Two Pointers and Sliding Window — quiz
11 multiple-choice questions covering Two Pointers, Sliding Window (Fixed), Sliding Window (Variable), Prefix Sums, Hash Map / Set Tricks. One answer each; you get a score at the end and the explanation for every question. No account needed.
Updated 2026-11-04. Keys 1–4 pick an answer, Enter moves on. Redo it any time, in order or shuffled.
The questions
Answers and explanations are shown after you finish.
- Two Pointers
You're using two pointers on a sorted array to find a pair that sums to a target value. The current sum of the pair exceeds the target. What should you do next?
- Move the left pointer right to increase the sum
- Restart the search with both pointers at the middle of the array
- Move the right pointer left to decrease the sum
- Move both pointers inward simultaneously regardless of the comparison
- Two Pointers
Which description correctly matches the two-pointer technique used to remove duplicates from a sorted array in place?
- A slow pointer marks the last confirmed unique position while a fast pointer scans ahead for new values
- A single pointer scans while a stack tracks duplicate values
- Two pointers start at both ends and swap elements while moving inward until they meet
- Two pointers move based on comparison to a target sum
- Sliding Window (Fixed)
To find all starting indices in a string s where an anagram of a shorter pattern p occurs, which approach correctly solves this?
- Binary search over possible starting indices in s
- A fixed-size sliding window of length len(p) combined with a character frequency map compared at each position
- A variable sliding window that grows until a duplicate character appears
- Sorting every substring of length len(p) and comparing it character by character to sorted p
- Sliding Window (Variable)
For finding the length of the smallest contiguous subarray whose sum is at least a target value, which window strategy applies?
- Start two pointers at both ends of the array and move them inward
- Shrink from the right while simultaneously expanding from the left
- Expand the right pointer to grow the sum, then shrink from the left while the sum condition still holds
- Keep the window at a fixed size equal to the length of the array
- Sliding Window (Variable)
In the sliding-window solution for 'longest substring without repeating characters,' what triggers shrinking the window from the left?
- Encountering a character that's already present in the current window
- The running sum exceeding a target value
- The right pointer reaching the end of the string
- The window reaching a fixed size k
- Prefix Sums
Given arr = [1,2,3,4], what is sum(1,3) (sum of elements from index 1 to 3 inclusive) using the prefix sum formula?
- 7
- 6
- 10
- 9
- Prefix Sums
Why is prefix sum combined with a hash map better suited than a sliding window for finding a subarray that sums to exactly k when the array may contain negative numbers?
- Hash maps are always faster than arrays for any kind of lookup
- Sliding window relies on the sum changing monotonically as the window grows, which breaks down with negative numbers, while prefix sum with a hash map still works
- Prefix sums eliminate the need to scan the array at all
- Sliding window only works when the array is already sorted
- Hash Map / Set Tricks
When finding two numbers in an unsorted array that sum to k using a hash map, what do you check at each element?
- Whether the current element has already been added to the map, and if so, remove it
- Whether the array has already been sorted in ascending order
- Whether the current element is less than k
- Whether the complement (k minus the current element) has already been seen and recorded in the map
- Fast & Slow Pointers
After the fast and slow pointers meet inside a linked list cycle, how do you determine the cycle's starting node?
- Reset one pointer to the head of the list, then advance both pointers one step at a time until they meet again
- Count the number of nodes between the two pointers at the point they met
- Reverse the entire linked list and rerun the fast and slow pointer algorithm
- Continue running the fast pointer alone until it loops back around to the meeting point
- Kadane's Algorithm
Why does the maximum product subarray variant of Kadane's algorithm need to track a running minimum in addition to a running maximum?
- The running minimum is needed to normalize the array before computing products
- Multiplying two negative numbers can turn the running minimum into the new maximum
- The minimum is always the final answer whenever the array has an even number of elements
- Running minimum prevents integer overflow during multiplication
- Merge Intervals
Intervals [2,6] and [5,10] are checked using the overlap condition a <= d and c <= b. Do they overlap?
- No, because 6 is less than 10
- Yes, because both intervals contain the number 10
- No, because 2 is less than 5
- Yes, because 2 <= 10 and 5 <= 6, satisfying the overlap condition
Try it with your own material
Paste notes, upload a PDF, or pick any of your decks and Quizcard writes a quiz with explanations in about a minute. Quizzes from your own decks are free.