AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content

06 Arrays / Checkpoint

Checkpoint — Arrays

22 min · +25 XP · 3 exercises · 12 questions

Exercises0/3
Quiz · 70% to clear12 q

This checkpoint covers array creation and indexing, two-dimensional and jagged arrays, the Arrays class and System.arraycopy, aliasing and copying, and the standard in-place patterns.

How it works. Twelve questions and two programs; 70% on the questions and both programs accepted clears the module.

Before you start, make sure you can answer:

  • What new String[3] contains, and what a.length is (field or method).
  • How many objects new int[3][4] creates, and what clone() copies on it.
  • What Arrays.asList(new int[]{1, 2}).size() returns.
  • Why a getter should return values.clone().
  • How to rotate an array in place, and why prefix arrays have n + 1 entries.

The programs are a matrix rotation and a prefix-sum range query — both classics that reward knowing the pattern.

Common questions

What does new String[3] contain in Java?

Three null references. Every slot of a new array starts at its type's default value, and for any reference type, String included, that default is null — so names[0].length() before any assignment throws a NullPointerException.

What does Arrays.asList(new int[]{1, 2}).size() return?

1. Arrays.asList does not box primitives, so the whole int[] becomes the list's single element and the result is a List<int[]>. Use Arrays.stream(a).boxed().toList() to get a List<Integer>.

Why does a prefix sum array have n + 1 entries?

The extra leading zero, prefix[0] = 0, lets every range sum be prefix[to] - prefix[from], including ranges that start at index 0, without a special case. prefix[i] is then the sum of the first i elements.

Java Arrays Quiz: 2D Arrays, Copying and Patterns Practice

Test your Java array skills with 12 questions and two programs on indexing, 2D and jagged arrays, the Arrays class, copying, rotation and prefix sums.

  • Course: Java study plan
  • Module: Arrays
  • Kind: Checkpoint — cleared at 70%
  • Reading time: 22 min
  • Runtime: OpenJDK 18

Checkpoint — Arrays is the checkpoint that closes the Arrays module: a graded quiz and whole-program exercises, passed at 70%.

Instructions

This checkpoint covers array creation and indexing, two-dimensional and jagged arrays, the Arrays class and System.arraycopy, aliasing and copying, and the standard in-place patterns.

How it works. Twelve questions and two programs; 70% on the questions and both programs accepted clears the module.

Before you start, make sure you can answer:

  • What new String[3] contains, and what a.length is (field or method).
  • How many objects new int[3][4] creates, and what clone() copies on it.
  • What Arrays.asList(new int[]{1, 2}).size() returns.
  • Why a getter should return values.clone().
  • How to rotate an array in place, and why prefix arrays have n + 1 entries.

The programs are a matrix rotation and a prefix-sum range query — both classics that reward knowing the pattern.

Common questions

What does new String[3] contain in Java?

Three null references. Every slot of a new array starts at its type's default value, and for any reference type, String included, that default is null — so names[0].length() before any assignment throws a NullPointerException.

What does Arrays.asList(new int[]{1, 2}).size() return?

  1. Arrays.asList does not box primitives, so the whole int[] becomes the list's single element and the result is a List<int[]>. Use Arrays.stream(a).boxed().toList() to get a List<Integer>.

Why does a prefix sum array have n + 1 entries?

The extra leading zero, prefix[0] = 0, lets every range sum be prefix[to] - prefix[from], including ranges that start at index 0, without a special case. prefix[i] is then the sum of the first i elements.

Exercises

Rotate a square matrix

Read an integer n, then an n × n grid of integers. Rotate it 90° clockwise in place — transpose (swap across the main diagonal, each pair once), then reverse each row — and print the result, one row per line, values space-separated.

Example: 3 then 1 2 3 / 4 5 6 / 7 8 9 →

7 4 1
8 5 2
9 6 3

Range sums with a prefix array

Read an integer n, then n integers (which may be negative and large), then an integer q and q queries l r (0-based, inclusive on both ends). Build a prefix-sum array of n + 1 longs once and answer every query in O(1). Print one sum per line.

Example: 5 then 1 2 3 4 5, 3 then 0 4, 1 3, 2 2 →

15
9
3

Pascal's triangle

Read an integer n (1 ≤ n ≤ 30). Build the first n rows of Pascal's triangle as a jagged long[][] — row i has i + 1 entries, each the sum of the two above it — and print each row space-separated. Then print rowSum=<sum of the last row> (which is 2^(n-1)) and middle=<the largest value in the last row>.

Example: 4 →

1
1 1
1 2 1
1 3 3 1
rowSum=8
middle=3

In this module: Arrays

← Array patterns — reverse, rotate, count, prefix sums · Classes, objects and references →