PRACTICE • LEARN • GROW
Arrays MCQs
Solve topic-wise placement questions and improve your skills.
Arrays Progress
0 of 25 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What will be the output of the following code snippet?
A.
int arr()
B.
int arr[5]
C.
array int[5]
D.
int[5] arr
Explanation & Key
Correct Answer:
2
Find the maximum subarray sum in the given array.
A.
O(n)
B.
O(log n)
C.
O(1)
D.
O(n^2)
Explanation & Key
Correct Answer:
3
Given an array, find the length of the longest increasing subsequence.
A.
Random memory blocks connected by pointers
B.
Sequentially in adjacent memory locations
C.
In heap as linked nodes
D.
In separate cache lines arbitrarily
Explanation & Key
Correct Answer:
4
Rotate an array to the right by k positions.
A.
Compiler throws a syntax error
B.
Throws ArrayIndexOutOfBoundsException
C.
Undefined behavior (garbage value or segmentation fault)
D.
Returns 0 automatically
Explanation & Key
Correct Answer:
5
Find the missing number in an array containing n distinct numbers.
A.
0
B.
1
C.
-1
D.
Variable based on OS
Explanation & Key
Correct Answer:
6
Which algorithm is used to find the maximum sum contiguous subarray in O(n) time?
A.
Dijkstra algorithm
B.
Kadane algorithm
C.
Kruskal algorithm
D.
Floyd-Warshall algorithm
Explanation & Key
Correct Answer:
7
What is the worst-case time complexity of inserting an element at the beginning of an array of size n?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Explanation & Key
Correct Answer:
8
Can array size be changed dynamically at runtime in C-style arrays?
A.
Yes, with realloc or new keywords
B.
No, static arrays have a fixed size allocated at creation
C.
Yes, automatically when full
D.
Only if compiled with -O3
Explanation & Key
Correct Answer:
9
What is the space complexity of Kadaneโs algorithm?
A.
O(n)
B.
O(1)
C.
O(log n)
D.
O(n^2)
Explanation & Key
Correct Answer:
10
Which technique is ideal for finding a pair of elements with a target sum in a sorted array in O(n) time?
A.
Two Pointers
B.
Depth First Search
C.
Dynamic Programming
D.
Prefix Trees
Explanation & Key
Correct Answer:
11
In a 2D array arr[R][C] stored in row-major order, what is the formula to locate arr[i][j]?
A.
base + (i * C + j) * size
B.
base + (j * R + i) * size
C.
base + (i + j) * size
D.
base + (i * R + j) * size
Explanation & Key
Correct Answer:
12
What is the advantage of using arrays over linked lists?
A.
Dynamic size
B.
Constant time O(1) random access and excellent cache locality
C.
O(1) insertion at any position
D.
No memory overhead for pointers
Explanation & Key
Correct Answer:
13
What is a prefix sum array useful for?
A.
Answering range sum queries in O(1) time
B.
Sorting an array in O(n) time
C.
Reversing an array in place
D.
Searching without indexing
Explanation & Key
Correct Answer:
14
What is the time complexity of the Dutch National Flag algorithm (3-way partitioning)?
A.
O(n^2)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Explanation & Key
Correct Answer:
15
Which of the following problems can be solved using the sliding window technique?
A.
Maximum sum subarray of fixed size k
B.
Finding topological ordering
C.
Shortest path in weighted graph
D.
Detecting cycles in directed graph
Explanation & Key
Correct Answer:
16
What does the amortized time complexity of inserting into a dynamic array (like std::vector or ArrayList) mean?
A.
Every single insertion takes exactly O(1)
B.
Average time per insertion over a sequence of insertions is O(1)
C.
Worst case insertion is always O(n^2)
D.
Resizing doubles the memory in O(1)
Explanation & Key
Correct Answer:
17
What is the time complexity to reverse an array of size n in place?
A.
O(1)
B.
O(n)
C.
O(n log n)
D.
O(n^2)
Explanation & Key
Correct Answer:
18
Which of the following algorithms sorts an array in O(n log n) worst-case time with O(1) auxiliary space?
A.
Merge Sort
B.
Quick Sort
C.
Heap Sort
D.
Bubble Sort
Explanation & Key
Correct Answer:
19
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, how can you find the missing number in O(n) time and O(1) space?
A.
Sum of first n natural numbers minus the array sum (or XOR)
B.
Sort the array and scan
C.
Use a hash set
D.
Binary search over unorganized array
Explanation & Key
Correct Answer:
20
In C++, what does `sizeof(arr) / sizeof(arr[0])` return when `arr` is a statically sized array?
A.
Total memory in bytes
B.
Number of elements in the array
C.
Pointer to the last element
D.
Memory address of arr[0]
Explanation & Key
Correct Answer:
21
What data structure is used internally by the Sliding Window Maximum problem to achieve O(n) time?
A.
Monotonic Deque
B.
Stack
C.
Binary Search Tree
D.
Disjoint Set Union
Explanation & Key
Correct Answer:
22
What is the minimum number of swaps needed to sort an array of size n in the worst case?
A.
n - 1
B.
n / 2
C.
n log n
D.
n^2
Explanation & Key
Correct Answer:
23
Which algorithm can find the majority element (occurring more than n/2 times) in O(n) time and O(1) space?
A.
Boyer-Moore Voting Algorithm
B.
Rabin-Karp Algorithm
C.
KMP Algorithm
D.
Aho-Corasick Algorithm
Explanation & Key
Correct Answer:
24
In Java, what is the default value of numeric elements in an uninitialized integer array `int[] arr = new int[5];`?
A.
null
B.
0
C.
undefined
D.
Garbage value
Explanation & Key
Correct Answer:
25
What is the time complexity of searching in a sorted 2D matrix where each row and column is sorted?
A.
O(R * C)
B.
O(R + C)
C.
O(log(R + C))
D.
O(1)
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong