Arrays and data structures · Interview questions · Updated November 2026
Array interview questions test whether you understand how arrays sit in memory, what each operation costs, and which pattern solves a problem in one pass: two pointers, sliding windows, prefix sums or Kadane’s algorithm. Interviewers also check language details, such as why a Python list or Java ArrayList can grow while a Java array cannot. This guide groups the topics, sets out what junior, mid-level and senior candidates should know, and gives a 2–3 week plan. It ends with 10 free array interview practice questions with answers, each explained.
At a glance
| Free in this post | 10 practice questions with answers |
| Levels covered | Junior, mid-level and senior |
| Core topics | Memory layout, dynamic arrays, searching, sorting |
| Common patterns | Two pointers, sliding window, prefix sums, Kadane |
| Languages in examples | Java, Python, JavaScript |
| Exametics set | 6 practice tests, 618 questions |
- Expect cost questions: indexing is constant time, while inserting at the front of an array moves every other element.
- Expect code-reading questions: what this snippet prints, and why.
Source: Python docs: Time complexity of operations on built-in types and Java Language Specification, Chapter 10: Arrays. Checked on 9 November 2026.
What interviewers test in array interview questions
Array interview questions test three things: how an array is stored, what each operation costs, and whether you can turn a brute-force loop into a one-pass solution. Stacks, binary heaps and dynamic lists are usually built on arrays, so clear answers here help in later rounds.
Memory layout and the cost of each operation
An array stores its elements next to each other, so the address of any element can be calculated from its index. That is why indexing is constant time. The NumPy ndarray documentation describes an array as “a contiguous one-dimensional segment of computer memory” combined with an indexing scheme.
Two-dimensional arrays still sit in one-dimensional memory. Row-major order, used in C and by default in NumPy, stores each row in full before the next. Column-major order, used in Fortran and Matlab, stores each column first. Looping row by row over a row-major array reads memory in stored order, which is usually faster.
Be ready to state the cost of the basic operations:
| Operation on a dynamic array | Typical cost |
|---|---|
| Read or write by index | O(1) |
| Append at the end | O(1) amortized |
| Insert or delete at position k | O(n − k): later elements move |
| Insert or delete at the front | O(n): the worst case |
| Search an unsorted array | O(n) |
| Binary search a sorted array | O(log n) |
The list rows match the Python time complexity page linked above, which marks append as amortized: one call may cost O(n) when the storage is resized, but the cost is spread over many calls.
Fixed-size and dynamic arrays
A classic opener is “what is the difference between an array and a list?” The answer depends on the language.
- Java arrays have a fixed length. The Java Language Specification says that once an array is created, its length never changes. Indexes run from 0 to n − 1, and every access is checked at run time: a bad index throws
ArrayIndexOutOfBoundsException. New arrays hold default values. - Java
ArrayListis a resizable array. The ArrayList documentation saysgetandsetrun in constant time andaddruns in amortized constant time. It does not publish a growth factor, so do not quote one as fact. - Python lists are dynamic arrays too. The Python design FAQ says CPython lists are “really variable-length arrays, not Lisp-style linked lists”, and extra space is allocated when they grow.
- JavaScript arrays are resizable, can mix types and can be sparse. The MDN Array reference notes that copies are shallow.
Searching and sorting
Searching questions usually lead to binary search, and the trap is its precondition. The Java Arrays documentation says the array must be sorted first, or the result is undefined. When the key is missing, Arrays.binarySearch returns -(insertion point) - 1, so a negative result still tells you where the key belongs.
Sorting questions check what the library does for you. The same Java page says Arrays.sort on primitives uses a Dual-Pivot Quicksort, while sorting objects is guaranteed stable. Python’s list.sort() sorts in place, returns None and is guaranteed stable. In JavaScript, the MDN sort reference warns that the default order compares elements as strings, so numbers need a comparator such as (a, b) => a - b.
Problem-solving patterns
Many array coding problems use one of five patterns. Learn the clue in the question that points to each one:
| Pattern | Clue in the question | How it works and its cost |
|---|---|---|
| Two pointers | A sorted array, or a question about pairs | Move one index from each end, or a slow and a fast index: O(n) time, O(1) extra space |
| Sliding window | “Contiguous subarray of length k” or “longest run that…” | Add the element entering the window and remove the one leaving it: O(n) time |
| Prefix sums | Many range-sum queries on an array that does not change | Build running totals once in O(n), then answer each query in O(1) |
| Kadane’s algorithm | Maximum-sum contiguous subarray | At each element, extend the current run or start again: one pass, O(1) extra space |
| Rotation in place | “Rotate by k” with no extra array | Three reversals: O(n) time, O(1) extra space |
Multidimensional, sparse and array-based structures
Matrix questions test index arithmetic and a classic Python bug. The Python programming FAQ shows that [[None] * 2] * 3 creates three references to the same row, so changing one row changes all three. In Java, the specification says cloning a multidimensional array is shallow: the subarrays are shared.
Sparse arrays are mostly zeros; the SciPy CSR reference lists the trade-offs of Compressed Sparse Row format: fast row slicing and matrix-vector products, slow column slicing, and costly changes to the sparsity structure.
For array-based structures, the Python collections documentation explains why a deque suits a queue better: it appends and pops at either end in about O(1), while a list pays O(n) on pop(0) and insert(0, v).
Exametics practice tests
Array Interview Questions Practice Tests
- 6 practice tests with 103 questions each: 618 questions in total
- Rebuilt for 2026: every answer key checked and every code question run
- Every answer explained, with a hint, and tagged with its topic area
- Timed Exam Mode test
- Lifetime access
30-day refund. Instant access after payment.
Array interview questions by level: junior, mid and senior
The level of the role changes the depth more than the topics: juniors explain what an array does, mid-level candidates solve problems with the right pattern, and seniors justify trade-offs in memory, speed and data structure choice.
| Level | What you should be able to do |
|---|---|
| Junior | Explain zero-based indexing, fixed versus dynamic arrays, the cost of indexing, inserting and searching, and how to loop over a 2D array. |
| Mid-level | Recognise two pointers, sliding window, prefix sums and Kadane’s algorithm, write them without off-by-one errors, and state time and space costs. |
| Senior | Choose between arrays, deques, heaps and sparse formats for a workload, explain amortized cost and memory layout, and discuss edge cases and in-place limits. |
Junior expectations
Junior questions check the basics: what happens when you read index n of an array of length n, or how to reverse an array in place. State the time and space cost after each answer.
Mid-level expectations
Mid-level rounds test patterns under time pressure. A typical question gives a brute-force O(n²) solution and asks you to improve it and test edge cases.
Senior expectations
Senior interviews add design reasoning. Why is a binary heap stored in an array rather than in linked nodes? Why is a CSR matrix good for row lookups but poor for frequent inserts?
Next on your data structures path
- Linked List Data Structures Interview practice tests: interviewers often ask you to compare arrays and linked lists.
- Data Structures and Algorithms practice tests: take your array skills on to trees, graphs and dynamic programming.
- Competitive Programming Mastery practice tests: useful if your coding rounds are timed.
How to prepare for array interview questions in 2–3 weeks
If you already code in one language, two to three weeks is enough: fundamentals first, then patterns, then timed practice.
- Days 1–3: memory and costs Write down the cost of each basic operation for your language’s array and dynamic list, and check it against the official documentation.
- Days 4–6: searching, sorting and rotation Write binary search from memory, including the “not found” case. Learn your library’s sort rules, such as stability and JavaScript’s string order. Rotate an array in place with three reversals.
- Days 7–10: the core patterns Solve three problems each for two pointers, sliding window, prefix sums and Kadane’s algorithm, stating time and space each time.
- Days 11–13: 2D, sparse and array-based structures Traverse a matrix by row and by column, build a 2D list correctly in Python, and implement a stack, a circular queue and a binary heap on an array.
- Days 14–18: timed practice Take the array interview practice tests in timed Exam Mode, read the explanation for every question you missed, and repeat the topic areas where you scored lowest.
Tip
Before you write code, state the brute-force cost, name your pattern and give the new cost. It shows your reasoning even if you run out of time.
Planning more than one exam?
The All-Access Pass covers every practice test on Exametics, including the 58 interview-question sets and new exams as they are added, with lifetime access. It costs less than buying about six single practice tests.
Free array interview practice questions (10 with answers)
Try these 10 free practice questions on arrays before opening the answers. They are original sample questions, each labelled with its topic area, and the full Exametics array practice test set has 618 more in the same style.
Practice question 1 · Memory layout
A NumPy array is created with np.zeros((3, 4), dtype=np.int64), so each element takes 8 bytes and the default row-major order is used. How many bytes from the start of the data block is element [2, 1]?
- A. 40
- B. 72
- C. 64
- D. 9
Show answer
Answer: B. In row-major order a full row of 4 elements (32 bytes) is stored before the next row starts. Element [2, 1] comes after two full rows and one more element: (2 × 4 + 1) × 8 = 72 bytes. This matches the strided formula in the NumPy documentation, with strides of 32 and 8 bytes.
A is the column-major (Fortran-order) answer: (1 × 3 + 2) × 8 = 40. C counts only the two full rows. D is the element’s position (9), not its offset in bytes.
Practice question 2 · Dynamic arrays
Which statement about adding elements to a Java ArrayList matches its official documentation?
- A. Every single
addcall is guaranteed O(1) in the worst case. - B.
ArrayListstores its elements as linked nodes, soaddnever copies data. - C. Each
addcosts O(log n) because the list stays balanced. - D. Adding n elements takes O(n) time in total, even though one
addmay cost more when the backing array grows.
Show answer
Answer: D. The ArrayList documentation says the add operation runs in amortized constant time, “that is, adding n elements requires O(n) time.” When the backing array is full it is replaced by a larger one, costing O(n) for that call, but this cost is spread across the cheap calls.
A confuses amortized with worst-case cost. B is wrong because ArrayList is a resizable-array implementation; LinkedList uses nodes. C is wrong: a list is not a balanced tree.
Practice question 3 · Initialization
What does this Python code print?grid = [[0] * 3] * 2grid[0][0] = 1print(grid)
- A.
[[1, 0, 0], [1, 0, 0]] - B.
[[1, 0, 0], [0, 0, 0]] - C.
TypeError, because lists cannot be multiplied - D.
[[1, 1, 1], [0, 0, 0]]
Show answer
Answer: A. The outer * 2 does not copy the inner list; it stores two references to the same list. Changing grid[0][0] changes that one shared row, so both rows show the 1. The Python programming FAQ describes this bug and suggests a list comprehension instead, such as [[0] * 3 for _ in range(2)].
B is the list-comprehension result, where each row is a separate list. C is wrong because multiplying a list by an integer is valid and repeats its items. D is wrong because the assignment changes only index 0 of the shared row; the other positions stay 0.
Practice question 4 · Searching
In Java, what does Arrays.binarySearch(new int[]{2, 5, 8, 12}, 6) return?
- A.
-1 - B.
2 - C.
-3 - D.
-2
Show answer
Answer: C. The key 6 is not in the array. The Java Arrays documentation says the method then returns -(insertion point) - 1, where the insertion point is the index of the first element greater than the key. That element is 8 at index 2, so the result is −2 − 1 = −3.
A assumes a fixed −1, but Java encodes the insertion point. B is the insertion point itself; returning it would look like a successful find. D forgets the “− 1”, which Java adds so that a key belonging at index 0 still gives a negative result.
Practice question 5 · Sorting
In JavaScript, what is the value of [10, 9, 1, 100].sort()?
- A.
[1, 9, 10, 100] - B.
[1, 10, 100, 9] - C.
[100, 10, 9, 1] - D. A
TypeError, becausesort()needs a compare function
Show answer
Answer: B. Without a compare function, MDN says the default order converts elements to strings and compares their UTF-16 code units. Strings compare character by character, and a shorter string that is a prefix of a longer one comes first, so “1” < “10” < “100”. All of them come before “9” because “1” < “9”.
A is the numeric order you get with sort((a, b) => a - b). C is a descending order, which the default never produces. D is wrong because the compare function is optional.
Practice question 6 · Rotation
You rotate [1, 2, 3, 4, 5, 6, 7] to the right by k = 10 in place. You first set k = k % n, then reverse the whole array, reverse the first k elements, and reverse the remaining elements. What is the result?
- A.
[4, 5, 6, 7, 1, 2, 3] - B.
[7, 1, 2, 3, 4, 5, 6] - C.
[1, 2, 3, 4, 5, 6, 7] - D.
[5, 6, 7, 1, 2, 3, 4]
Show answer
Answer: D. With n = 7, k becomes 10 % 7 = 3. Reversing the whole array gives [7, 6, 5, 4, 3, 2, 1]; reversing the first 3 gives [5, 6, 7, 4, 3, 2, 1]; reversing the last 4 gives [5, 6, 7, 1, 2, 3, 4]. The method runs in O(n) time with O(1) extra space.
A is a rotation to the left by 3. B is a right rotation by only 1. C would be right only if k were a multiple of 7.
Practice question 7 · Prefix sums
You build a prefix array P of length n + 1, where P[0] = 0 and P[i + 1] = P[i] + a[i]. Which expression gives the sum of a[i] to a[j], inclusive, for any valid 0 ≤ i ≤ j < n?
- A.
P[j] - P[i] - B.
P[j + 1] - P[i + 1] - C.
P[j + 1] - P[i] - D.
P[j] - P[i - 1]
Show answer
Answer: C. P[k] holds the sum of the first k elements, a[0] to a[k − 1]. P[j + 1] is the sum up to a[j], and subtracting P[i] removes everything before a[i]. Each query then costs O(1) after an O(n) build.
A leaves out a[j]. B leaves out a[i]. D mixes the two indexing styles: it leaves out a[j] and adds a[i − 1], and when i = 0 it reads P[-1], which is out of range in Java and wraps to the last element in Python.
Practice question 8 · Two pointers
To find two numbers that add up to a target in an array sorted in ascending order, you start with left = 0 and right = n - 1. The current pair’s sum is smaller than the target. What should you do next?
- A. Move
leftone step to the right. - B. Move
rightone step to the left. - C. Move both pointers one step towards the middle.
- D. Reset
righttoleft + 1and scan forward again.
Show answer
Answer: A. The array is sorted, so moving left right is the only move that can increase the sum. The old left value can be dropped: even with the largest remaining value its sum was too small. Each step removes one candidate, so the search takes O(n) time and O(1) space.
B makes the sum smaller, moving away from the target. C changes both values at once and can skip the correct pair. D turns the method back into the O(n²) brute-force search.
Practice question 9 · Kadane’s algorithm
What is the maximum sum of a non-empty contiguous subarray of [3, -4, 5, -1, 2, -6, 4]?
- A. 6
- B. 14
- C. 5
- D. 4
Show answer
Answer: A. Kadane’s algorithm keeps the best sum ending at each position: 3, then max(−4, 3 − 4) = −1, then max(5, −1 + 5) = 5, then 4, then 6, then 0, then 4. The best value seen is 6, from the subarray [5, -1, 2].
B adds all the positive numbers, but they are not contiguous. C is the single largest element, which is smaller than 6. D is the last element on its own or the best sum ending at the final position, not the best overall.
Practice question 10 · Sliding window
Using a fixed-size sliding window, what is the largest sum of any 3 consecutive elements in [2, 1, 5, 1, 3, 2]?
- A. 8
- B. 9
- C. 10
- D. 7
Show answer
Answer: B. The first window [2, 1, 5] sums to 8. Sliding one step at a time, add the new element and subtract the one leaving: 8 − 2 + 1 = 7, then 7 − 1 + 3 = 9, then 9 − 5 + 2 = 6. The largest is 9, from [5, 1, 3], found in O(n) time instead of re-adding every window.
A is only the first window. C adds the three largest values (5 + 3 + 2), which are not consecutive. D is the second window, not the largest.
How did you score?
8–10 correct: you are ready for a full timed test, so try Exam Mode next. Under 8: go back to the topic areas you missed and practise them again. The array interview practice tests have 618 more questions like these, each with a hint and a full explanation.
Common mistakes in array interviews
Marks in array rounds are often lost to off-by-one errors, unstated assumptions and confusing one language’s rules with another’s.
- Off-by-one errors at the edges. Valid indexes run from 0 to n − 1. Check loop bounds, window edges and prefix-sum indexes on a three-element example before you say “done”.
- Calling append “always O(1)”. It is amortized O(1); one call can cost O(n) when the array is resized.
- Using binary search on unsorted data. Sort first, or say why the input is sorted. The Java documentation calls the result on unsorted input undefined.
- Building a 2D list with
*in Python. All rows share one list. Use a list comprehension. - Sorting numbers with JavaScript’s default
sort(). It compares strings, so pass(a, b) => a - b. - Skipping edge cases. Test an empty array, one element, all negatives and duplicates.
Array interview questions: FAQs
What do array interview questions cover?
They cover how arrays are stored in memory, the cost of indexing, inserting and searching, fixed versus dynamic arrays, sorting and binary search, and patterns such as two pointers, sliding windows, prefix sums and Kadane’s algorithm. Senior roles add multidimensional and sparse arrays and array-based structures such as heaps and queues.
Are there free array interview practice questions?
Yes. This post includes 10 free array interview sample questions with answers and explanations, each labelled with its topic area. For a full timed practice test, the Exametics array interview practice tests have 618 questions in 6 tests, including Exam Mode.
How many questions are in the Exametics array interview practice tests?
There are 6 practice tests with 103 questions each, 618 questions in total, including a timed Exam Mode test. Every question explains why the right answer is right and why the others are wrong, and includes a hint.
Is a Python list the same as an array?
Not exactly, but it is built on one. The Python design FAQ says CPython lists are variable-length arrays of references, so indexing costs the same whatever the list size, and the list grows by allocating extra space.
Are array interview questions hard?
The basics are easy to learn, but interviews raise the difficulty by asking for an O(n) solution where the obvious one is O(n²). If you can name the right pattern and explain its time and space cost, most array questions become manageable.
Which language should I use to practise arrays?
Use the language you will code in during the interview, and learn its own rules. For example, Java arrays have a fixed length, Python lists and Java ArrayList grow automatically, and JavaScript sorts numbers as strings unless you pass a compare function.
How long does it take to prepare for array interview questions?
If you already code in one language, two to three weeks of focused study is usually enough: memory and costs, then searching, sorting and the core patterns, then timed practice. Allow more time if complexity analysis is new to you.
Official documentation: Java SE 21 Arrays class. Checked on 9 November 2026.
Practise array interview questions with full practice tests
Work through 618 array interview questions in six practice tests, from memory layout to sliding windows, with a hint and a full explanation for every answer and a timed Exam Mode test.
✓ Every answer explained · ✓ Timed exam mode · ✓ 30-day refund