Question 11
EasyWhich technique reverses an array in place?
- A.
Hashing
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
Which technique reverses an array in place?
Hashing
A sliding window
Two pointers, swapping the elements at both ends and moving inwards
Binary search
Sign up free to see the answer and a step-by-step explanation.
What extra space does the two-pointer pair-sum method on a sorted array use?
O(n)
O(log n)
O(n²)
O(1)
Sign up free to see the answer and a step-by-step explanation.
Using a sliding window, what is the largest sum of 3 consecutive elements in [2, 1, 5, 1, 3, 2]?
9
8
6
14
Sign up free to see the answer and a step-by-step explanation.
When a fixed-size sliding window moves one step to the right, how is its sum updated?
Add the new element on the right and subtract the element that left on the left
Double the old sum
Recompute the whole sum
Subtract the new element
Sign up free to see the answer and a step-by-step explanation.
Which problem is a classic use of a variable-size sliding window?
Reversing a linked list
Finding the median of two arrays
Sorting an array
Longest substring without repeating characters
Sign up free to see the answer and a step-by-step explanation.
How are two sorted arrays merged into one sorted array in linear time?
With a hash table
By sorting the concatenation with bubble sort
With one pointer in each array, always taking the smaller current element
With binary search for each element
Sign up free to see the answer and a step-by-step explanation.
Which technique removes duplicates from a sorted array in place?
A slow pointer for the next write position and a fast pointer that scans
A min-heap
A stack
Binary search
Sign up free to see the answer and a step-by-step explanation.
Moving all zeros to the end of an array while keeping the order of the other elements can be done in:
O(log n) time
O(n log n) time only
O(n) time with two pointers
O(n²) time only
Sign up free to see the answer and a step-by-step explanation.
When checking whether 'madam' is a palindrome with two pointers, which characters are compared first?
The last two
The first two
The middle one with itself
The first and the last
Sign up free to see the answer and a step-by-step explanation.
With a sliding window, what is the time complexity of finding the sums of all windows of size k in an array of n elements?
O(n)
O(n·k)
O(n²)
O(k)
Sign up free to see the answer and a step-by-step explanation.