AP CSA Array & ArrayList Mini FRQs - Write Real Code (Interactive)

Interactive — Write Real Code

AP CSA Array & ArrayList Mini FRQs

8 exam-level problems. Write your solution, run it, and get instant auto-graded feedback. This is how you build FRQ confidence.

AP CSA Exam: May 15, 2026. Reading about arrays is not enough. You need to write the code yourself.
How it works: Each problem gives you a method signature. Write your implementation in the editor. Click Run & Grade to execute your code against hidden test cases. You will see a pass or fail result with your output vs expected output. Click Show Solution if you get stuck. Your code runs in a live Java environment — real compilation, real execution.
Your Score 0 / 8 passed

Remove All Occurrences

Write a method removeAll that takes an ArrayList and an int target, and removes ALL occurrences of target from the list. The method modifies the list in place and returns nothing.

Hint: Traverse backwards to avoid index-shifting bugs.
Solution:
public static void removeAll(ArrayList list, int target)
{
    for (int i = list.size() - 1; i >= 0; i--)
    {
        if (list.get(i) == target)
        {
            list.remove(i);
        }
    }
}

Remove Duplicates

Write a method removeDuplicates that takes an ArrayList and removes duplicate values, keeping only the first occurrence of each. Modifies the list in place.

Hint: For each element, check if it appeared earlier in the list.
Solution:
public static void removeDuplicates(ArrayList list)
{
    for (int i = list.size() - 1; i >= 1; i--)
    {
        for (int j = 0; j < i; j++)
        {
            if (list.get(i).equals(list.get(j)))
            {
                list.remove(i);
                break;
            }
        }
    }
}

Shift Left

Write a method shiftLeft that takes an int[] and shifts every element one position to the left. The first element wraps around to the last position.

Hint: Save the first element, shift everything left, then put the saved value at the end.
Solution:
public static void shiftLeft(int[] arr)
{
    if (arr.length <= 1)
    {
        return;
    }
    int first = arr[0];
    for (int i = 0; i < arr.length - 1; i++)
    {
        arr[i] = arr[i + 1];
    }
    arr[arr.length - 1] = first;
}

Reverse Array In Place

Write a method reverse that reverses an int[] in place. Do not create a new array.

Hint: Swap elements from the outside in, using two index variables moving toward the center.
Solution:
public static void reverse(int[] arr)
{
    int left = 0;
    int right = arr.length - 1;
    while (left < right)
    {
        int temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        left++;
        right--;
    }
}

Filter to New List

Write a method filterAbove that takes an int[] and an int threshold, and returns a new ArrayList containing only elements greater than threshold.

Hint: Create a new ArrayList, loop through the array, add elements that pass the condition.
Solution:
public static ArrayList filterAbove(int[] arr, int threshold)
{
    ArrayList result = new ArrayList();
    for (int i = 0; i < arr.length; i++)
    {
        if (arr[i] > threshold)
        {
            result.add(arr[i]);
        }
    }
    return result;
}

Count Long Strings

Write a method countLong that takes a String[] and an int minLen, and returns the number of Strings whose length is greater than or equal to minLen.

Hint: Standard accumulator pattern with a length condition.
Solution:
public static int countLong(String[] words, int minLen)
{
    int count = 0;
    for (int i = 0; i < words.length; i++)
    {
        if (words[i].length() >= minLen)
        {
            count++;
        }
    }
    return count;
}

Swap Adjacent Pairs

Write a method swapPairs that takes an int[] and swaps every pair of adjacent elements. If the array has odd length, the last element stays in place.

Hint: Loop with step 2. Swap arr[i] and arr[i+1].
Solution:
public static void swapPairs(int[] arr)
{
    for (int i = 0; i < arr.length - 1; i += 2)
    {
        int temp = arr[i];
        arr[i] = arr[i + 1];
        arr[i + 1] = temp;
    }
}

Row Sums (2D Array)

Write a method rowSums that takes a int[][] and returns a new int[] where each element is the sum of the corresponding row.

Hint: Create a result array with grid.length elements. Nested loop to sum each row.
Solution:
public static int[] rowSums(int[][] grid)
{
    int[] sums = new int[grid.length];
    for (int r = 0; r < grid.length; r++)
    {
        int total = 0;
        for (int c = 0; c < grid[r].length; c++)
        {
            total += grid[r][c];
        }
        sums[r] = total;
    }
    return sums;
}
Final Score 0 / 8 passed

Want Structured FRQ Practice Every Day?

The 4-Week Cram Kit includes daily FRQ drills with scoring rubrics for every problem type.

Get the Cram Kit — $29.99 1-on-1 Tutoring

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]