An ordered collection of values stored together under a single name and accessed by their numeric index position. Arrays allow you to store, retrieve, and manipulate multiple related values efficiently using loops and index-based access.
A numbered list. Item 0, item 1, item 2... Access any by its number.
Showing a random 20 of 50 problems.
Example 1
medium
Array `a = [10, 20, 30, 40, 50]`. What is `a[a[0]/10]`?
Example 2
hard
Linear search needs at most how many comparisons to find a value in an array of length n (worst case)?
Example 3
medium
Array `a = [9, 7, 5, 3, 1]`. What is `a[len(a) - 1]`?a = [9, 7, 5, 3, 1] โ a[len(a)-1] = a[4]; what value does it hold?
Example 4
medium
Given `scores = [12, 15, 9, 20]`, what are `scores[0]` and `scores[3]`, and what happens if code tries to read `scores[4]`?scores = [12, 15, 9, 20] โ identify scores[0], scores[3], and what scores[4] means
Example 5
easy
Array `a = [3, 1, 4, 1, 5]`. After `a[1] = 9`, what is the array?After a[1] = 9, the array [3, 1, 4, 1, 5] becomes [3, 9, 4, 1, 5]
Example 6
medium
To insert a value at index 1 in an array of length 6 (no resize cost), how many existing elements must shift right?
Example 7
medium
Write pseudocode to count how many elements of `nums = [3, 7, 2, 9, 4]` are greater than 5. What is the count?
Example 8
medium
Array `a = [9, 3, 7, 1, 5]`. After ascending sort, what is `a[2]`?After sorting [9, 3, 7, 1, 5] ascending โ [1, 3, 5, 7, 9]; what is a[2]?
Example 9
easy
Array `a = [11, 22, 33, 44, 55]`. What is `a[0]`?a = [11, 22, 33, 44, 55] โ what value is at index 0?
Example 10
medium
Array `a = [3, 1, 4, 1, 5, 9]`. What is `a[1] + a[4]`?
Example 11
easy
Array `a = [4, 4, 4]`. What is the sum of all elements?
Example 12
medium
Sum every element of `a = [10, 20, 30, 40]` using indices 0 to length-1. What is the sum?
Example 13
medium
Fill in the blank: To loop over every element of an array of length n, indices range from 0 to ____.
Example 14
medium
Array `a = [5, 3, 8, 1]`. After sorting ascending, what is `a[0]`?After sorting [5, 3, 8, 1] ascending โ [1, 3, 5, 8]; what is a[0]?
Example 15
medium
Sum every element of `a = [3, 5, 7]` by looping indices 0 to length-1. What is the sum?
Example 16
easy
Array `a = [1, 2, 3]`. What happens with `a[3]`?
Example 17
easy
Array `a = [11, 22, 33, 44, 55]`. What is `a[4]`?a = [11, 22, 33, 44, 55] โ what value is at the last index 4?
Example 18
hard
You want to swap the FIRST and LAST elements of an array of length 6 without overwriting either. What is the minimum number of assignments needed?
Example 19
medium
Reverse `a = [1, 2, 3, 4]` by swapping a[i] with a[n-1-i]. What is `a[3]` paired with for swapping when i=0?
Example 20
medium
Reverse `a = [1,2,3,4,5]` by swapping `a[i]` with `a[n-1-i]`. After processing i=0 and i=1, what is the array?