Question 11
EasyWhich exception does Java throw when an array is accessed with an invalid index?
- 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
Which exception does Java throw when an array is accessed with an invalid index?
ArithmeticException
IndexError
ArrayIndexOutOfBoundsException
NullPointerException
Sign up free to see the answer and a step-by-step explanation.
What is a dynamic array?
An array that grows automatically when it fills up, such as Python's list or C++'s vector
An array of pointers only
An array stored on disk
An array that changes its values randomly
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of removing the last element of a dynamic array?
O(n)
O(n²)
O(log n)
O(1)
Sign up free to see the answer and a step-by-step explanation.
What does Kadane's algorithm find?
The maximum sum of a contiguous subarray
The median of the array
The number of inversions
The second largest element
Sign up free to see the answer and a step-by-step explanation.
What is a subarray?
An array inside a function
Any selection of elements in any order
A contiguous part of an array
The first element only
Sign up free to see the answer and a step-by-step explanation.
What is a subsequence of an array?
Any rearrangement of the elements
Elements taken in their original order, not necessarily next to each other
The array sorted
A contiguous block of elements
Sign up free to see the answer and a step-by-step explanation.
How many non-empty subarrays does an array of n elements have?
n
n²
n(n + 1)/2
2ⁿ
Sign up free to see the answer and a step-by-step explanation.
What does reversing an array in place cost?
O(log n) time
O(n) extra space
O(n) time and O(1) extra space
O(n²) time
Sign up free to see the answer and a step-by-step explanation.
What is [1, 2, 3, 4, 5] after rotating it left by 2 positions?
[3, 4, 5, 1, 2]
[2, 3, 4, 5, 1]
[4, 5, 1, 2, 3]
[5, 4, 3, 2, 1]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [1, 2, 3]
b = a
b.append(4)
print(len(a))
3
Error
Sign up free to see the answer and a step-by-step explanation.
4
1