Question 41
MediumWhat is the time complexity of checking whether s is a subsequence of t using two pointers?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the time complexity of checking whether s is a subsequence of t using two pointers?
O(|s| × |t|)
O(2^|s|)
O(log |t|)
O(|s| + |t|)
Sign up free to see the answer and a step-by-step explanation.
Which technique finds the longest substring with at most k distinct characters?
Binary search
A sliding window with a character-count map
Sorting
Dynamic programming over all pairs
Sign up free to see the answer and a step-by-step explanation.
For sliding windows with a fixed size k, how is the next window sum obtained?
Sort the window
Multiply by k
Add the new element and subtract the one leaving the window
Recompute the whole sum
Sign up free to see the answer and a step-by-step explanation.
Why can't a sliding window find the longest subarray with sum k when the array has negative numbers?
The array must be sorted
Shrinking the window no longer always decreases the sum, so the window can't be moved greedily
Negative numbers can't be added
It can, always
Sign up free to see the answer and a step-by-step explanation.
How do you merge two sorted arrays in place when the first has enough space at the end?
Fill from the front
Concatenate and sort
Use a heap
Fill from the back, comparing the largest remaining elements
Sign up free to see the answer and a step-by-step explanation.
How do the slow and fast pointers find the middle of a linked list?
Fast moves 3 steps
Slow moves 1 step and fast moves 2; when fast reaches the end, slow is at the middle
Both move 1 step
By counting nodes twice
Sign up free to see the answer and a step-by-step explanation.
Which problem is NOT typically solved with two pointers on a sorted array?
Pair with a given sum
Removing duplicates in place
Finding the shortest path in a graph
Merging two sorted arrays
Sign up free to see the answer and a step-by-step explanation.
Reversing a string in place with two pointers takes how much extra space?
O(n²)
O(n)
O(1)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of the sliding-window approach for 'longest substring without repeating characters'?
O(2ⁿ)
O(n²)
O(n)
O(n log n)
Sign up free to see the answer and a step-by-step explanation.
Partitioning an array around a pivot (as in quick sort) uses which pointer technique?
Two pointers moving towards each other or one scanning pointer with a boundary
Recursion only
A heap
A stack
Sign up free to see the answer and a step-by-step explanation.