1What is the time complexity of binary search on a sorted array of elements?
Iterative and recursive binary search
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Binary search halves the search space in each step, giving a logarithmic time complexity of .
Incorrect! Try again.
2Binary search requires the input array to be:
Iterative and recursive binary search
Easy
A.Sorted
B.Filled with unique negative numbers
C.Unsorted
D.Reversed only
Correct Answer: Sorted
Explanation:
Binary search relies on comparing the target with the middle element to discard half the array, which only works if the array is sorted.
Incorrect! Try again.
3In binary search, how is the middle index typically computed to avoid integer overflow for indices and ?
Iterative and recursive binary search
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Using prevents overflow that could occur from directly adding and when both are large.
Incorrect! Try again.
4For an array of size , what is the optimal block (jump) size used in jump search?
Jump search
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Jumping by minimizes the total work, giving jump search its time complexity of .
Incorrect! Try again.
5Like binary search, jump search requires the array to be:
Jump search
Easy
A.Containing only even numbers
B.Circular
C.Sorted
D.Empty
Correct Answer: Sorted
Explanation:
Jump search skips ahead in fixed blocks and relies on ordering to know when the target has been passed, so the array must be sorted.
Incorrect! Try again.
6What does sublist search (list matching) determine?
Sublist search
Easy
A.Whether a list is present as a contiguous part of another list
B.The largest element in a linked list
C.The sum of all elements in a list
D.Whether a list is sorted in ascending order and contains no duplicate values at all
Correct Answer: Whether a list is present as a contiguous part of another list
Explanation:
Sublist search checks if all elements of one linked list appear consecutively within another list.
Incorrect! Try again.
7For an array containing distinct numbers from to , which formula gives the missing number using the sum approach?
Find the missing number
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
The expected sum of to is ; subtracting the actual array sum yields the missing number.
Incorrect! Try again.
8Which bitwise operation is commonly used to find a single missing number without risk of overflow?
Find the missing number
Easy
A.AND
B.OR
C.NOT
D.XOR
Correct Answer: XOR
Explanation:
XOR-ing all indices with all elements cancels matching pairs, leaving only the missing number.
Incorrect! Try again.
9What is the time complexity of searching an element in a sorted and rotated array using modified binary search?
Search an element in a sorted and rotated array
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
A modified binary search still halves the search space each step, achieving even on rotated arrays.
Incorrect! Try again.
10In a sorted and rotated array, at each step of modified binary search we first check:
Search an element in a sorted and rotated array
Easy
A.Which half is properly sorted
B.The average of the whole array
C.Whether the array is empty
D.The last element only
Correct Answer: Which half is properly sorted
Explanation:
Identifying the sorted half lets us decide whether the target lies within it, allowing us to discard the other half.
Incorrect! Try again.
11What does a substring search function return when the pattern is found in the text?
Recursive function to perform substring search
Easy
A.The length of the text
B.The number of vowels in the pattern
C.The reversed pattern
D.The starting index of the match
Correct Answer: The starting index of the match
Explanation:
Substring search typically reports the position where the pattern begins within the text.
Incorrect! Try again.
12In a naive recursive substring search, what happens at each recursive call?
Recursive function to perform substring search
Easy
A.The entire text is deleted from memory and rebuilt each time before comparison
B.The function attempts to match the pattern starting at the next position
C.The pattern is doubled in length
D.The text is sorted alphabetically
Correct Answer: The function attempts to match the pattern starting at the next position
Explanation:
Each recursive call shifts the starting index and tries to match the pattern against that portion of the text.
Incorrect! Try again.
13Which data structure is most suitable for counting how many times each word appears in a string?
Find the K most frequent words from a string
Easy
A.Queue
B.Stack
C.Hash map (dictionary)
D.Linked list
Correct Answer: Hash map (dictionary)
Explanation:
A hash map stores each word as a key with its count as the value, allowing efficient frequency counting.
Incorrect! Try again.
14When two words have the same frequency, they are often ordered by:
Find the K most frequent words from a string
Easy
A.Reverse insertion order always
B.Lexicographical (alphabetical) order
C.Number of vowels
D.String length only
Correct Answer: Lexicographical (alphabetical) order
Explanation:
Ties in frequency are commonly broken by sorting the words alphabetically.
Incorrect! Try again.
15For finding a pair with a given difference in a sorted array, which technique gives an efficient solution?
Find a pair with a given difference
Easy
A.Matrix multiplication
B.Depth-first search
C.Two-pointer approach
D.Bubble sort
Correct Answer: Two-pointer approach
Explanation:
Two pointers move through the sorted array adjusting based on the current difference, achieving linear time.
Incorrect! Try again.
16To find a pair with difference , if we fix an element , which value do we search for?
Find a pair with a given difference
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
A pair has difference when , so we search for .
Incorrect! Try again.
17A peak element in an array is one that is:
Find a peak element
Easy
A.Smaller than all other elements
B.Always at the last index
C.Greater than or equal to its neighbors
D.Equal to the array's average value
Correct Answer: Greater than or equal to its neighbors
Explanation:
A peak is an element not smaller than its adjacent elements; boundaries consider only their single neighbor.
Incorrect! Try again.
18What is the time complexity of finding a peak element using binary search?
Find a peak element
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
By comparing the middle element with its neighbor and moving toward the higher side, a peak is found in time.
Incorrect! Try again.
19Which technique is commonly combined with prefix sums to efficiently handle subarray sum range problems?
Length of longest subarray having sum in given range l r
Easy
A.Sliding window / two pointers
B.Graph coloring
C.Randomized quicksort
D.Recursion tree only
Correct Answer: Sliding window / two pointers
Explanation:
Prefix sums together with sliding window or two-pointer techniques let us evaluate subarray sums efficiently.
Incorrect! Try again.
20The naive brute-force method to print all subarrays with sum in a range has what time complexity?
Print all subarrays with sum in a given range
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Considering every possible start and end index of a subarray and tracking running sums leads to pairs.
Incorrect! Try again.
21In an iterative binary search, the mid index is computed as mid = low + (high - low) / 2 instead of mid = (low + high) / 2. What is the primary reason for this choice?
Iterative and recursive binary search
Medium
A.To reduce the number of recursive calls made by the algorithm
B.To ensure the array remains sorted during the search
C.To make the search run in time instead of
D.To avoid integer overflow when low and high are large
Correct Answer: To avoid integer overflow when low and high are large
Explanation:
Adding low + high can exceed the integer range for large values. Writing low + (high - low) / 2 yields the same midpoint while keeping the intermediate sum within bounds.
Incorrect! Try again.
22A recursive binary search is called on a sorted array of elements. In the worst case, how many recursive calls (including the initial call) are made before termination?
Iterative and recursive binary search
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Each call halves the search space, so the depth of recursion is about , giving calls in the worst case.
Incorrect! Try again.
23For a sorted array of elements, what block (jump) size minimizes the worst-case number of comparisons in jump search?
Jump search
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
With block size , the cost is about , which is minimized when , giving the optimal time.
Incorrect! Try again.
24Jump search is being applied to an array of 100 sorted elements using the optimal block size. Approximately how many total comparisons does it need in the worst case?
Jump search
Medium
A.About 20
B.About 50
C.About 100
D.About 7
Correct Answer: About 20
Explanation:
Optimal block size is . Worst case does about comparisons.
Incorrect! Try again.
25Sublist search checks whether a linked list of nodes appears as a contiguous sublist within a larger linked list of nodes. What is its worst-case time complexity using the naive approach?
Sublist search
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
For each of the starting positions, up to nodes are compared, giving in the worst case, similar to naive substring matching.
Incorrect! Try again.
26An array contains distinct numbers taken from the range to . Using the sum formula, which expression correctly gives the missing number?
Find the missing number
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The sum of all numbers from to is . Subtracting the actual array sum yields the missing value.
Incorrect! Try again.
27Which technique finds the single missing number in a range to without risking overflow from summation and works in time?
Find the missing number
Medium
A.XOR all array elements with all numbers from to
B.Use a hash set that maps each number to its frequency, then scan the whole map to detect which key is absent from the sequence
C.Sort the array and binary search for the gap
D.Repeatedly divide the range and count elements in each half
Correct Answer: XOR all array elements with all numbers from to
Explanation:
XOR-ing every array element with every number in to cancels all matching pairs, leaving the missing number. It avoids overflow and runs in .
Incorrect! Try again.
28In a sorted and rotated array with no duplicates, after computing mid, how do you decide which half to search in modified binary search?
Search an element in a sorted and rotated array
Medium
A.Determine which half is sorted, then check if the target lies within that sorted half's range
B.Search both halves recursively and merge the results
C.Compare the target only with the first and last elements
D.Always discard the right half if the target is greater than arr[mid]
Correct Answer: Determine which half is sorted, then check if the target lies within that sorted half's range
Explanation:
At least one half is always sorted. Identify it, test if the target falls within its bounds, and recurse into the appropriate half, keeping the search .
Incorrect! Try again.
29Consider the rotated array [6, 7, 8, 1, 2, 3, 4, 5]. When searching for 3, the first mid (index 3, value 1) is examined. Which half is identified as sorted?
Search an element in a sorted and rotated array
Medium
A.Both halves are equally sorted
B.Neither half is sorted
C.The right half [1, 2, 3, 4, 5] is sorted
D.The left half [6, 7, 8, 1] is sorted
Correct Answer: The right half [1, 2, 3, 4, 5] is sorted
Explanation:
Since arr[mid]=1 \le arr[high]=5, the right half is sorted. The target 3 lies in , so the search continues in the right half.
Incorrect! Try again.
30A recursive substring search checks if pattern P occurs in text T starting at each index. What is the base case that returns success?
Recursive function to perform substring search
Medium
A.All characters of P have been matched (pattern index reaches its length)
B.The text index reaches the end of T
C.The lengths of P and T become equal
D.The first characters of P and T are equal
Correct Answer: All characters of P have been matched (pattern index reaches its length)
Explanation:
A full match occurs when the recursion has compared every character of the pattern successfully, i.e., the pattern index equals its length.
Incorrect! Try again.
31To find the most frequent words in a string, a min-heap of size is maintained over word frequencies. What is the overall time complexity if there are distinct words?
Find the K most frequent words from a string
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Each of the distinct words is pushed/popped from a heap of size , costing per operation, for a total of .
Incorrect! Try again.
32When two words have the same frequency in the "K most frequent words" problem, the standard tie-breaking rule ranks them by which criterion?
Find the K most frequent words from a string
Medium
A.Reverse alphabetical order
B.Length of the word, longest first
C.Lexicographical (alphabetical) order
D.Order of first appearance in the string
Correct Answer: Lexicographical (alphabetical) order
Explanation:
The conventional rule breaks frequency ties by returning words in lexicographically ascending order so the output is deterministic.
Incorrect! Try again.
33Given a sorted array, the two-pointer method finds a pair with difference . When arr[j] - arr[i] > d, what action is taken?
Find a pair with a given difference
Medium
A.Reset both pointers to the start
B.Increment j to increase the larger element
C.Increment i to increase the smaller element
D.Decrement j to reduce the difference
Correct Answer: Increment i to increase the smaller element
Explanation:
If the difference is too large, moving i forward increases arr[i], which shrinks the gap arr[j] - arr[i] toward the target .
Incorrect! Try again.
34For an unsorted array, which approach finds a pair with a given difference in average time using extra space?
Find a pair with a given difference
Medium
A.Use two nested loops to compare every pair of elements
B.Sort the array first, then apply binary search for each element
C.Build a balanced BST and traverse it in order to detect the pair
D.Store elements in a hash set, then for each x check if x + d exists
Correct Answer: Store elements in a hash set, then for each x check if x + d exists
Explanation:
Insert all values into a hash set; for each element x, checking whether x + d is present takes average time, giving overall .
Incorrect! Try again.
35A peak element is one that is not smaller than its neighbors. Using binary search, if arr[mid] < arr[mid+1], where is a peak guaranteed to exist?
Find a peak element
Medium
A.Only at the boundaries of the array
B.In the right half, indices mid+1 to high
C.Exactly at index mid
D.In the left half, indices low to mid
Correct Answer: In the right half, indices mid+1 to high
Explanation:
Since the sequence rises toward mid+1, moving right must eventually reach a peak (values can't rise forever within bounds), so search the right half.
Incorrect! Try again.
36What is the time complexity of finding a peak element in an unsorted array using the binary search approach?
Find a peak element
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The binary search variant discards half the array each step based on the neighbor comparison, achieving even though the array is unsorted.
Incorrect! Try again.
37To find the longest subarray whose sum lies in , prefix sums are used. For a fixed right index with prefix sum , the subarray sum condition becomes which inequality on an earlier prefix ?
Length of longest subarray having sum in given range l r
Medium
A. only
B.
C.
D.
Correct Answer:
Explanation:
The subarray sum is . Requiring rearranges to .
Incorrect! Try again.
38For an array of all positive integers, why does the sliding-window technique work to enumerate subarrays with sum in a range?
Print all subarrays with sum in a given range
Medium
A.Because the array must be sorted before sliding
B.Because the running sum increases monotonically as the window expands, so the window can be shrunk once the sum exceeds the range in a controlled manner that never requires re-examining discarded left elements
C.Because negative numbers cancel out the positives
D.Because prefix sums are unnecessary for positive arrays
Correct Answer: Because the running sum increases monotonically as the window expands, so the window can be shrunk once the sum exceeds the range in a controlled manner that never requires re-examining discarded left elements
Explanation:
With only positive values, expanding the window always increases the sum and shrinking it always decreases it, giving the monotonicity that sliding-window relies on.
Incorrect! Try again.
39Machines produce items at fixed rates. To find the minimum time to make items, binary search is applied on the answer (time ). What is checked for a candidate time ?
Minimum time required to produce m items
Medium
A.Whether divides evenly among the machines
B.Whether the fastest machine alone can produce items
C.Whether the total items produced by all machines in time is at least
D.Whether each machine individually produces items in time
Correct Answer: Whether the total items produced by all machines in time is at least
Explanation:
Sum over all machines; if it is , time is feasible, and binary search narrows to the minimum such .
Incorrect! Try again.
40If the slowest machine takes max_rate minutes per item and there are machines producing items, what is a valid upper bound for the binary search on time?
Minimum time required to produce m items
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Even a single slowest machine could make all items in minutes, so that is a safe upper bound for the search range.
Incorrect! Try again.
41In a binary search implementation, using mid = (low + high) / 2 can cause a bug for very large arrays. Why does mid = low + (high - low) / 2 fix this?
Iterative and recursive binary search
Hard
A.It prevents integer overflow when low + high exceeds the maximum integer value
B.It handles duplicate elements more correctly than the naive form
C.It guarantees the search always terminates in time
D.It reduces the number of comparisons per iteration by one
Correct Answer: It prevents integer overflow when low + high exceeds the maximum integer value
Explanation:
For large low and high, their sum can overflow a fixed-width integer, producing a negative or wrong index. Rewriting as low + (high - low) / 2 keeps intermediate values within range while computing the same midpoint.
Incorrect! Try again.
42A recursive binary search is written with base case if (low > high) return -1. If instead a programmer writes if (low >= high) return -1, what is the consequence?
Iterative and recursive binary search
Hard
A.An element at a position where low == high may be missed, causing false negatives
C.It converts the search into linear time complexity
D.It always returns the first element regardless of the target
Correct Answer: An element at a position where low == high may be missed, causing false negatives
Explanation:
When the search narrows to a single element, low == high. Using >= terminates before checking that element, so a target present only at that index is never found.
Incorrect! Try again.
43For a sorted array of size , jump search uses a block size of . What block size minimizes the worst-case number of comparisons, and what is that optimal complexity?
Jump search
Hard
A., giving
B., giving
C., giving
D., giving
Correct Answer: , giving
Explanation:
Total cost is roughly (jumps plus the linear scan within a block). Minimizing over gives , yielding .
Incorrect! Try again.
44Why is jump search generally preferred over binary search on systems where jumping backward is far costlier than jumping forward (e.g., certain tape/streaming media)?
Jump search
Hard
A.Jump search only steps backward once during the final linear scan, minimizing costly reverse seeks
B.Jump search has a lower asymptotic complexity than binary search
C.Jump search requires the array to be unsorted, avoiding reordering
D.Jump search never needs to move backward at all
Correct Answer: Jump search only steps backward once during the final linear scan, minimizing costly reverse seeks
Explanation:
Jump search moves forward in blocks and only steps back once to linearly scan the identified block. Binary search jumps back and forth repeatedly, which is expensive on media where reverse access is slow.
Incorrect! Try again.
45Sublist search checks whether a linked list S appears as a contiguous sublist of list L. What is the worst-case time complexity of the straightforward approach for lengths and ?
Sublist search
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The naive sublist search tries to match S starting from each node of L. In the worst case each of the starting positions requires up to comparisons, giving .
Incorrect! Try again.
46During sublist search, a partial match fails after matching nodes of the pattern. In the naive algorithm, from which node of the main list does the next matching attempt begin?
Sublist search
Hard
A.From the node where the mismatch occurred
B.From the head of the main list again
C.From nodes ahead of the current position
D.From the node immediately after the original start of the failed attempt
Correct Answer: From the node immediately after the original start of the failed attempt
Explanation:
The naive sublist search does not use failure-function backtracking. After a mismatch it resets the pattern pointer and restarts matching from the node right after where the current attempt began.
Incorrect! Try again.
47An array contains distinct numbers from the range with exactly one missing. Using XOR to find the missing number, what is XORed together?
Find the missing number
Hard
A.XOR of all array elements XORed with XOR of all integers from to
B.XOR of all array indices XORed with the array sum
C.XOR of the first and last array elements only
D.XOR of all array elements XORed with
Correct Answer: XOR of all array elements XORed with XOR of all integers from to
Explanation:
XOR-ing all elements with all values cancels every present number (since ), leaving only the missing value. This avoids overflow risks of the sum-based method.
Incorrect! Try again.
48For finding one missing number in , the sum formula uses . Compared to the XOR method, what is the main practical drawback of the sum approach?
Find the missing number
Hard
A.The sum can overflow for large , while XOR never overflows
B.The sum method has worse time complexity than XOR
C.The sum method fails when the array is sorted
D.The sum method requires extra space
Correct Answer: The sum can overflow for large , while XOR never overflows
Explanation:
Both are time and space, but the sum grows quadratically and may overflow fixed-width integers. XOR operates bitwise and stays bounded, avoiding overflow.
Incorrect! Try again.
49In a sorted rotated array with no duplicates, at each step of the modified binary search you compute mid. How do you decide which half is normally sorted?
Search an element in a sorted and rotated array
Hard
A.If arr[mid] <= arr[high], the left half is sorted; otherwise the right half
B.If arr[low] > arr[high], both halves are sorted
C.If arr[low] <= arr[mid], the left half is sorted; otherwise the right half is sorted
D.If arr[mid] == arr[low], neither half is sorted
Correct Answer: If arr[low] <= arr[mid], the left half is sorted; otherwise the right half is sorted
Explanation:
Because rotation creates one contiguous sorted region containing low..mid or mid..high. If arr[low] <= arr[mid] the left portion is in order, so you can test whether the target lies within it and discard the other half.
Incorrect! Try again.
50When a sorted rotated array contains duplicates, why can the worst-case time complexity of the search degrade to ?
Search an element in a sorted and rotated array
Hard
A.Duplicates double the recursion depth of the search
B.Duplicates make integer overflow in the midpoint unavoidable
C.When arr[low] == arr[mid] == arr[high], neither half can be determined as sorted, forcing a linear shrink
D.Duplicates cause the array to become unsorted, requiring a full sort first
Correct Answer: When arr[low] == arr[mid] == arr[high], neither half can be determined as sorted, forcing a linear shrink
Explanation:
With duplicates the equality arr[low] == arr[mid] == arr[high] gives no information about which side is sorted, so the algorithm can only advance low or shrink high by one, degrading to in the worst case.
Incorrect! Try again.
51A recursive substring search matches pattern P inside text T. The base cases are: pattern exhausted (return true) and text exhausted with pattern remaining (return false). What recursive relation correctly continues a match?
Recursive function to perform substring search
Hard
A.If P[0] == T[0], return true; else recurse on P[1:] and T
B.If P[0] == T[0], recurse on P[1:] and T[1:]; else recurse on the same P with T[1:]
C.Always recurse on both P[1:] and T[1:] regardless of match
D.If P[0] == T[0], recurse on P and T[1:]; else return false immediately
Correct Answer: If P[0] == T[0], recurse on P[1:] and T[1:]; else recurse on the same P with T[1:]
Explanation:
On a character match, advance both pointers to continue the current alignment. On mismatch, the whole pattern must be retried from the next text position, so the pattern resets while the text advances by one.
Incorrect! Try again.
52For a recursive naive substring search over text of length and pattern of length , what is the worst-case time complexity, and which inputs trigger it?
Recursive function to perform substring search
Hard
A., e.g. text "aaaa...a" with pattern "aaa...b"
B., when text is shorter than the pattern
C., always, due to recursion memoization
D., when the pattern is a palindrome
Correct Answer: , e.g. text "aaaa...a" with pattern "aaa...b"
Explanation:
Repeated near-matches force the pattern to re-match from nearly every text position. With a text of all a's and a pattern of a's ending in a mismatching char, each of positions does comparisons, giving .
Incorrect! Try again.
53To find the most frequent words (ties broken by lexicographic order) from a string with distinct words, using a min-heap of size , what is the time complexity?
Find the K most frequent words from a string
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
After counting frequencies, each of the distinct words is pushed into a min-heap capped at size ; heap operations cost . This gives , better than fully sorting at when .
Incorrect! Try again.
54When using a min-heap to keep the top- frequent words, the comparator must order words so the least desirable candidate sits at the root for eviction. For equal frequencies, how should the comparator rank words?
Find the K most frequent words from a string
Hard
A.Words that are lexicographically larger should be treated as smaller so they are evicted first
B.Ties should be broken by insertion order into the heap
C.Words that are lexicographically smaller should be treated as smaller so they are evicted first
D.Ties should be broken by word length, shorter first
Correct Answer: Words that are lexicographically larger should be treated as smaller so they are evicted first
Explanation:
In a min-heap keeping the best , the root is the weakest kept candidate. With equal counts we prefer the lexicographically smaller word, so the larger one must compare as 'smaller' to sit at the root and be evicted first.
Incorrect! Try again.
55Given a sorted array, to find a pair with difference using two pointers i and j, how are the pointers advanced?
Find a pair with a given difference
Hard
A.Move both pointers inward from the two ends until they meet
B.If arr[j] - arr[i] < d increment i; if > d increment j; if == d report success
C.Increment j only, checking arr[j] - arr[0] each time
D.If arr[j] - arr[i] < d increment j; if > d increment i; if == d (and i != j) report success
Correct Answer: If arr[j] - arr[i] < d increment j; if > d increment i; if == d (and i != j) report success
Explanation:
Both pointers start near the front. Increasing j raises the difference; increasing i lowers it. This monotonic control finds a pair in after sorting, versus per binary-search variant.
Incorrect! Try again.
56For an unsorted array, a hash-set method finds a pair with difference by checking, for each element , whether or was seen. What subtle case must be handled when ?
Find a pair with a given difference
Hard
A.The set must be sorted before insertion
B.The value overflows and must be skipped
C.A number must appear at least twice; a single occurrence must not falsely report a pair
D.Only even numbers can form a valid zero-difference pair
Correct Answer: A number must appear at least twice; a single occurrence must not falsely report a pair
Explanation:
With , , so a single element would match itself and give a false positive. The algorithm must ensure the value genuinely occurs at least twice before reporting a pair.
Incorrect! Try again.
57In an array where arr[i] != arr[i+1] for all i, a peak is an element not smaller than its neighbors. Binary search finds a peak in . Which decision rule is correct at index mid?
Find a peak element
Hard
A.Always search the half with the smaller boundary value
B.If arr[mid] < arr[mid+1], a peak must exist to the right; else search left including mid
C.If arr[mid] < arr[mid+1], a peak must exist to the left; else search right
D.If arr[mid] > arr[mid-1], always return mid as the peak
Correct Answer: If arr[mid] < arr[mid+1], a peak must exist to the right; else search left including mid
Explanation:
If the right neighbor is larger, the ascending slope guarantees a peak somewhere to the right. Otherwise mid is on a non-increasing side toward the left, where a peak is guaranteed, so we search left including mid.
Incorrect! Try again.
58Why does the peak-finding binary search always guarantee a peak exists in the chosen half, even without global sorting?
Find a peak element
Hard
A.Moving toward a larger neighbor guarantees a boundary that eventually turns down, forcing a peak in that direction
B.Because every array of distinct elements has exactly one peak
C.Because the midpoint is always a local minimum
D.Because the array is implicitly sorted after each halving step
Correct Answer: Moving toward a larger neighbor guarantees a boundary that eventually turns down, forcing a peak in that direction
Explanation:
If you always step toward the larger neighbor, the sequence keeps rising but is bounded, so it must eventually stop rising—that turning point is a peak. This guarantees a peak in the retained half regardless of the rest of the array.
Incorrect! Try again.
59For an array with negative numbers, why does the simple sliding-window (two-pointer) technique fail to find the longest subarray with sum in range ?
Length of longest subarray having sum in given range l r
Hard
A.Sliding window only works for fixed-length subarrays
B.The array must be sorted before applying sliding window
C.Prefix sums are not monotonic, so expanding or shrinking the window does not move the sum predictably
D.Negative numbers make all subarray sums negative
Correct Answer: Prefix sums are not monotonic, so expanding or shrinking the window does not move the sum predictably
Explanation:
Sliding window relies on the sum increasing as the window grows. With negatives the prefix sum is non-monotonic, so shrinking the window may increase the sum—breaking the invariant. Prefix sums with ordered structures (e.g., BIT/BST) are used instead.
Incorrect! Try again.
60Given machines where machine produces one item every minutes, binary search on time finds the minimum to make items. What monotonic predicate is searched?
Minimum time required to produce m items
Hard
A., monotonic in
B., true only at the largest
C. exactly, for a unique
D., which is false for small and true for large
Correct Answer: , which is false for small and true for large
Explanation:
In time , machine makes items. Total production is monotonic non-decreasing in , so binary search finds the smallest where .
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →