Question 21
EasyWhat is the output of this code?
a = [5, 1, 4]
a.sort()
(a[] + 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 output of this code?
a = [5, 1, 4]
a.sort()
(a[] + a[-])
10
6
5
9
Sign up free to see the answer and a step-by-step explanation.
What is the maximum sum of a contiguous subarray of [−2, 1, −3, 4, −1, 2, 1, −5, 4]?
4
6
7
10
Sign up free to see the answer and a step-by-step explanation.
For the 2D array [[1, 2, 3], [4, 5, 6]], what is a[1][2] (0-based indices)?
3
6
5
2
Sign up free to see the answer and a step-by-step explanation.
What is the prefix-sum array of [2, 4, 1, 3]?
[10, 8, 4, 3]
[2, 4, 1, 3]
[2, 6, 7, 10]
[2, 8, 8, 24]
Sign up free to see the answer and a step-by-step explanation.
What is a sparse matrix?
A matrix with no rows
A matrix of random numbers
A matrix in which most elements are zero
A matrix with only one column
Sign up free to see the answer and a step-by-step explanation.
Which operation is O(1) on an array but O(n) on a linked list?
Counting elements one by one
Traversing all elements
Inserting at the front
Accessing an element by its index
Sign up free to see the answer and a step-by-step explanation.
What is the second largest value in [10, 20, 4, 45, 99]?
99
10
20
45
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
best = cur = a[0]
for x in a[1:]:
cur = max(x, cur + x)
best = max(best, cur)
print(best)
5
6
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [1, 2, 3, 4]
for i in range(1, len(a)):
a[i] += a[i - 1]
print(a)
[1, 3, 6, 10]
[1, 2, 3, 4]
Sign up free to see the answer and a step-by-step explanation.
Using a prefix-sum array, how fast can you answer 'sum of elements from index l to r'?
O(1) per query after O(n) preprocessing
O(n²) per query
O(log n) per query
O(n) per query
Sign up free to see the answer and a step-by-step explanation.
7
4
[1, 3, 5, 7]
[10, 6, 3, 1]